Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
November 12, 2007, 9:37 pm
rate this thread
I try to use mysqli object instead of standard mysql functions.
Is it ok to create mysqli object within my class or schould I pass
mysqli object to my object.
The problem is, with code below I must call mysqli->connect() each
time I call class methods. How do I create an connection for hole
object, so methods can do queries without connect each time?
Best Regards, Michael
$a = new MyClass();
//here other stuf with connections to other databases
//and so on...
var one = '';
var mysqli = '';
$this->mysqli = new mysqli() //with all needed parameters
$this->mysqli->connect() //with all needed parameters
//my stuff here with mysqli query
/ /my stuff here with another mysqli query
Re: How to use mysqli object in object, need advise
First of all, you'll find it easier to derive your class from mysqli.
You'll then be able to call the mysqli functions directly from your
program (or override them in your class, as necessary).
For instance, you could create a connect() function with calls
parent::connect() with the appropriate parameters.
But either way, you should only need to connect when you create a new
MyClass object. If you use the same object multiple places in your
page, you should be able to just keep using the same connection.
Unfortunately, you didn't show us more of the code so we can see what's
Remove the "x" from my email address
JDS Computer Training Corp.