[Phplib-trackers] [ phplib-Bugs-450642 ] db_mysql.inc loses database
Brought to you by:
nhruby,
richardarcher
|
From: <no...@so...> - 2001-08-23 21:52:12
|
Bugs item #450642, was opened at 2001-08-13 15:48 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=403611&aid=450642&group_id=31885 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Richard Archer (richardarcher) Assigned to: Nobody/Anonymous (nobody) Summary: db_mysql.inc loses database Initial Comment: Nathan's bug report from the NetUSE bugs forum. Sorry about the whacked formatting... it didn't copy/paste well.-- Problem: When using phplib with mysql, phplib sets the default database. If the application uses another database, then phplib fails on page_close(); Fix: the following diff db_mysql.inc.new db_mysql.inc.old show the changes that allow phplib to access the database defined in local.inc independently of what the application uses for a database. This problem probably on show up if the user/pass is the same on both databases because mysql reuses the connection handle. This fix avoids the problem. diff db_mysql.inc db_mysql.inc.save 80,83c80,83 < # if (!@mysql_select_db($Database,$this->Link_ID)) { < # $this->halt("cannot use database ".$this->Database); < # return 0; < # } --- > if (!@mysql_select_db($Database,$this->Link_ID)) { > $this->halt("cannot use database ".$this->Database); > return 0; > } 117c117 < $this->Query_ID = @mysql_db_query($this->Database, $Query_String,$this->Link_ID); --- > $this->Query_ID = @mysql_query($Query_String,$this->Link_ID); 185c185 < $res = @mysql_db_query($this->Database, $query, $this->Link_ID); --- > $res = @mysql_query($query, $this->Link_ID); 196c196 < $res = @mysql_query("unlock tables", $this->Link_ID); # unrelated fix --- > $res = @mysql_query("unlock tables"); 244c244 < $id = @mysql_db_query($this->Database, $q, $this->Link_ID); --- > $id = @mysql_query($q, $this->Link_ID); 254c254 < $id = @mysql_db_query($this->Database, $q, $this->Link_ID); --- > $id = @mysql_query($q, $this->Link_ID); 263c263 < $id = @mysql_db_query($this->Database, $q, $this->Link_ID); --- > $id = @mysql_query($q, $this->Link_ID); ---------------------------------------------------------------------- >Comment By: Richard Archer (richardarcher) Date: 2001-08-23 14:52 Message: Logged In: YES user_id=279311 Attached a fixed db_sql.inc file from Guillaume ---------------------------------------------------------------------- Comment By: Martin Larsen (mlarsen) Date: 2001-08-21 22:21 Message: Logged In: YES user_id=295363 I agree that deriving a new db class would be the correct way to go, but I also think that phplib should be able to handle a user which manually switches database. AFAIR there is also an issue with PHP/MySQL being "confused" when your having two db-classes with two different databases if you use the same username/password combination for those two. I am not sure if this is related to using mysql_pconnect as I have not tried it myself. Should be easy to test though... ---------------------------------------------------------------------- Comment By: Giancarlo Pinerolo (pingus) Date: 2001-08-21 12:09 Message: Logged In: YES user_id=163488 But shouldn't one be supposed to derive a new db class if using a different database? This is the correct way, I think. One class, one db. Two db? Two subclasses. Giancarlo ---------------------------------------------------------------------- Comment By: Martin Larsen (mlarsen) Date: 2001-08-21 10:58 Message: Logged In: YES user_id=295363 As I see it we have two options here: 1) In page_close change the database back to the original. This isn't "nice" as it's a rather nasty side-effect. On the other hand page_close is usually called in the end of a script and therefore it usually wouldn't matter if we change the database. 2) In CT_SQL.inc we could fully qualify the tablenames with "database.tablename" instead of "tablename". I guess this would also solve the problem? I guess option 2 is the "cleanest" but I might have missed something... ---------------------------------------------------------------------- Comment By: Martin Larsen (mlarsen) Date: 2001-08-21 10:42 Message: Logged In: YES user_id=295363 For some reason unknow to me mysql_db_query is marked deprecated since PHP 4.0.6. The manual suggest using mysql_use_db() and mysql_query() instead but in that case we seems to miss a mysql_get_current_db() function. It wouldn't be "nice" to just switch the database with mysql_use_db() without setting it back but I can't see any way for us to know which database the user switched to. :-( ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=403611&aid=450642&group_id=31885 |