Reply to How to use mysqli object in object, need advise

Your name:

Reply:


Posted by Michael on 11/12/07 21:37

Hi,

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

$a->connectToDB($mydb);
$a->methode1();

//and so on...

?>


class MyClass{
var one = '';
var mysqli = '';

function __construct(){
$this->mysqli = new mysqli() //with all needed parameters
}
function connectToDB($db){
$this->mysqli->connect() //with all needed parameters

}

function methode1(){
//my stuff here with mysqli query
}

function methode2(){
/ /my stuff here with another mysqli query
}

}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация