Thread: [Phplib-users] db_mysql.inc connect() & multiple databases
Brought to you by:
nhruby,
richardarcher
From: Mike G. <mi...@op...> - 2002-07-19 19:38:18
|
Hello, I'm just looking at db_mysql.inc now and it looks to me like it is structured such that the database criticals need to be hard coded into the defaults for the file: function connect($Database = db $Host = "localhost", $User = "user", $Password = "password") { I can't see a way around this without rewriting this clas so that it does not depend on the connect() function only using the default values. Shouldn't it just be pulling $Database, $Host, $User & $Password from the main script's config file? If there's a reason why it needs to be defined in two places I'd be interested in knowing.. I was hoping to just use a single instance of phplib to run a number of different sites (all accessing different databases on the same server) Mike -- Mike Gifford, OpenConcept Consulting, http://www.openconcept.ca Open Source Web Applications for Social Change. Featured Client - NDP Leadership Candidate - http://www.billblaikie.org "An unjust law is no law at all." - Saint Augustine |
From: Mike G. <mi...@op...> - 2002-07-20 20:56:08
|
I mostly wanted to thank folks for the answers that I got to my question.. Stepped away from this project for a while (amazing what you can forget in the summer's heat).. Mike ps. If anyone's interested in checking out the latest version of Back-end CMS, please let me know.. It's using a lot more of phplib and we're just about ready to make the first alpha release. It's heavily based on phpSlash's structure (but allows for a multi-lingual (content & navigation), hierarchical CMS. -- Mike Gifford, OpenConcept Consulting, http://www.openconcept.ca Open Source Web Applications for Social Change. Featured Client - NDP Leadership Candidate - http://www.billblaikie.org "An unjust law is no law at all." - Saint Augustine |
From: Richard A. <rh...@ju...> - 2002-07-20 00:27:24
|
At 15:38 -0400 19/7/02, Mike Gifford wrote: >I'm just looking at db_mysql.inc now and it looks to me like it is >structured such that the database criticals need to be hard coded into >the defaults for the file: This works for me: $db = new DB_SQL; $db->Host = "localhost:3306"; $db->Database = "test"; $db->User = "tester"; $db->Password = "testing"; $db2 = new DB_SQL; $db2->Host = "localhost:3306"; $db2->Database = "test2"; $db2->User = "tester"; $db2->Password = "testing"; ...R. |
From: Michael C. <mdc...@mi...> - 2002-07-20 02:44:53
|
On Fri, Jul 19, 2002 at 03:38:09PM -0400, Mike Gifford wrote: > Hello, > > I'm just looking at db_mysql.inc now and it looks to me like it is > structured such that the database criticals need to be hard coded into > the defaults for the file: > > function connect($Database = db $Host = "localhost", $User = "user", > $Password = "password") { > > I can't see a way around this without rewriting this clas so that it > does not depend on the connect() function only using the default > values. > > Shouldn't it just be pulling $Database, $Host, $User & $Password from > the main script's config file? Actually, it's pulling those values from properties which are overridden in a subclass. You should see something like this in local.inc: class DB_Mine extends DB_Sql { var $Host = "localhost"; var $Database = "mydb"; var $User = "mydbuser"; var $Password = "mydbpass"; } Then, in your code: $db = new DB_Mine; I've found that it's often more convenient to put the subclass code about into a file other than local.inc so that you can easily move that file between a test and production environment which have different databases. Michael -- Michael Darrin Chaney mdc...@mi... http://www.michaelchaney.com/ |
From: Mike G. <Mik...@sa...> - 2002-07-20 12:54:10
|
YAW (yet another way) ;-) I had one case where $db_host, $db_database, etc. were required to be in a separate file which contained only configuration information. I, therefore, put lines in setup.inc which looked like: $db_host = "localhost"; // database host $db_database = "fred"; // database name $db_user = "jane"; // database user name $db_password = "apple72"; // database user password Then in the extension to DB_Sql (in local.inc) these values were accessed via the constructor: class DB_Mine extends DB_Sql { // constructor function DB_Mine ($query = "") { global $db_host, $db_database, $db_user, $db_password; $this->Host = $db_host; $this->Database = $db_database; $this->User = $db_user; $this->Password = $db_password; $this->DB_Sql($query); } ... } And then, as Michael says, in the code: $db = new DB_Mine(); Cheers! Mike Green Michael Chaney wrote: > On Fri, Jul 19, 2002 at 03:38:09PM -0400, Mike Gifford wrote: > > Hello, > > > > I'm just looking at db_mysql.inc now and it looks to me like it is > > structured such that the database criticals need to be hard coded into > > the defaults for the file: > > > > function connect($Database = db $Host = "localhost", $User = "user", > > $Password = "password") { > > > > I can't see a way around this without rewriting this clas so that it > > does not depend on the connect() function only using the default > > values. > > > > Shouldn't it just be pulling $Database, $Host, $User & $Password from > > the main script's config file? > > Actually, it's pulling those values from properties which are overridden > in a subclass. You should see something like this in local.inc: > > class DB_Mine extends DB_Sql { > var $Host = "localhost"; > var $Database = "mydb"; > var $User = "mydbuser"; > var $Password = "mydbpass"; > } > > Then, in your code: > > $db = new DB_Mine; > > I've found that it's often more convenient to put the subclass code > about into a file other than local.inc so that you can easily move > that file between a test and production environment which have > different databases. > > Michael > -- > Michael Darrin Chaney > mdc...@mi... > http://www.michaelchaney.com/ > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Phplib-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phplib-users -- _______________________________________________________________________ Michael D Green SaeSolved:: Custom-Built Web Applications -- http://www.saesolved.com 1552 Beachview Drive, Virginia Beach, VA 23464-7225, USA; 757.467.1552 http://www.everypeople.net http://www.sitewidgets.com _______________________________________________________________________ |
From: S. <bj...@ba...> - 2002-07-20 15:38:43
|
Hi, * Mike Gifford wrote: > I'm just looking at db_mysql.inc now and it looks to me like it is db_mysql.inc ist the wrong way to look at. PHPLIB's nature is configuring via local.inc where you subclass DB_Sql. If you don't want to hardcode it, use constants (which may come from a more general config file): class DBmy extends DB_Sql { var $Host = DB_HOST; var $Database = DB_DATABASE; } -- When the heart of your company - your website - gets out of balance. When the small problem from monday will be a big problem on Friday before the RollOut. * te...@th... We help you. Within 2 hours. * +49 (0)931/7843804 |