Re: MDB::setOptions & singleton
| From: | Lukas Smith | Date: | Tue, 20 Jan 2004 10:00:15 +0000 |
| Subject: | Re: MDB::setOptions & singleton | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10232@lists.php.net to get a copy of this message | ||
Vincent DUPONT wrote:
Hello everyone, I have 2 questions about MDB 1) Is this the right way to use the MDB::setOptions method? It seems to work...actually you would want to do: $this->connection = MDB::connect($dsn,array('optimize'=>'portability')); You have to set the options once per session.$this->connection = MDB::connect($dsn);MDB::setOptions($this->connection, array('optimize'=>'portability')) ;Is this set once forever Or do I need to set the option every time I instanciate a new connection?
2) what exactly is the benefit of using the sigleton method? Is this working between classes? My root class instanciates a MDB object, and all children classes do a connection to any of 3 databases. Can I reuse the connections accross classes? What happen if I call a close() in one class?if you dont pass a dsn it will give you any instance of MDB if one exists or it will return a pear error. if you pass a dsn it will give you an existing instance of MDB that has the same dsn as you have passed or it will create a new instance this means that you dont necessarily need to pass your MDB instances around, however the singleton method of course adds some overhead. if you call disconnect() on an instance you should not use it anymore one important things to note: MDB connects on demand, so you can switch the DSN as often as you like and MDB will make sure that your query is done against the current DSN. regards, Lukas