Re: [Phplib-users] db_mysql.inc connect() & multiple databases
Brought to you by:
nhruby,
richardarcher
|
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
_______________________________________________________________________
|