Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

DB Connection mysqli/functions.

mysqli oop referencing

Best Answer Overload, 21 December 2013 - 08:25 AM

Fixed this issue by passing pointers to the constructor.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 Overload

Overload

    CC Regular

  • Member
  • PipPipPip
  • 29 posts

Posted 21 December 2013 - 07:28 AM

Hi Guys,

 

Been at this a while and its driving my mad, so I have a a class to grab the DB info, it grabs a reference of $this. to grab the whole class.

 

Then I assign it to a var in another class constructer

$this->sql = $sql;

So when I go to run the runQuery function within the class it errors with:

Fatal error: Call to a member function runQuery() on a non-object

 

I have tried the following:

$this->sql->runQuery();

Can anyone point me where I am going wrong?

 

Thanks,

Adam



#2 Overload

Overload

    CC Regular

  • Member
  • PipPipPip
  • 29 posts

Posted 21 December 2013 - 08:25 AM   Best Answer

Fixed this issue by passing pointers to the constructor.



#3 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts

Posted 03 January 2014 - 12:05 AM

Another way is to create a database wrapper using the "singleton" pattern. This way you don't need to pass pointers, just create a method to retrieve the db object from the wrapper.


I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download