Login   Register  
PHP Classes
elePHPant
Icontem

Override DB paremeter

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Extended MySQLi  >  All threads  >  Override DB paremeter  >  (Un) Subscribe thread alerts  
Subject:Override DB paremeter
Summary:Override DB paremeter
Messages:5
Author:Valentino Lauciani
Date:2010-06-08 12:11:36
Update:2010-06-10 08:26:48
 

  1. Override DB paremeter   Reply  
Picture of Valentino Lauciani
Valentino Lauciani
2010-06-08 12:11:36
Hello

I am using your great class to query my DBs.

Unfortunately I have to interact with multiple databases with different USER and PASSOWRD.
Instead of creating copies of the config.php file, how I can override a variable:
DBHOST
DBUSER
DBPASS
DBNAME
DBPORT

Thank you.

  2. Re: Override DB paremeter   Reply  
Picture of Camilo Sperberg
Camilo Sperberg
2010-06-09 16:10:20 - In reply to message 1 from Valentino Lauciani
Hi Valentino, thanks for your feedback :)

Unfortunately you can't do this with this class unless you modify it. (A lot). Why? Because only 1 db instance can be invoked with this class so trying to connect simultaneously to another with be pointless according to the class's basic principles.

If you really want to do this, I suggest taking out the DB_connect class and on the __construct method of the DB_mysql class adding this:

[code]
@$this->db=new mysqli($host,$user,$pass,$name,$port);
if (mysqli_connect_error()) die(mysqli_connect_error());
else $this->connected = TRUE;
[/code]

creating the class as:

$myLink = new DB_mysql('host','user','pass','dbname'[,port]);

That should do the trick.

Greetings !

  3. Re: Override DB paremeter   Reply  
Picture of Valentino Lauciani
Valentino Lauciani
2010-06-09 19:50:38 - In reply to message 2 from Camilo Sperberg
Hello and thanks for your reply.

If I understand correctly, you're telling me that a solution might be to copy the class "DB_Connect" in a new file (for example db_connect.php) and then change its constructor?

When you said "on the __construct method of the class DB_mysql adding" what class do you mean? Class "DB_Connect" into new file db_connect.php?

Thank you and sorry for requesting clarification.

  4. Re: Override DB paremeter   Reply  
Picture of Camilo Sperberg
Camilo Sperberg
2010-06-10 03:52:08 - In reply to message 3 from Valentino Lauciani
oh no no no ... if you look carefully, you can see that the package are 2 classes. You should just (only) delete the DB_connect class. If you want to connect to multiple databases, that class (which avoids cloning AKA establishing another connection) is useless to you.

So, you should just delete it.


In the remaining class, you should apply on the __construct method all the changes previously exposed.

Greetings !!

  5. Re: Override DB paremeter   Reply  
Picture of Valentino Lauciani
Valentino Lauciani
2010-06-10 08:26:48 - In reply to message 4 from Camilo Sperberg
Thank you very very much.

It works!