Mantis - Quercus
Viewing Issue Advanced Details
2880 major always 08-29-08 00:05 09-05-08 15:59
koreth  
nam  
high  
closed 3.2.1  
fixed  
none    
none 3.2.1  
0002880: MySQL code assumes only one database name is ever used
Say you have two MySQL servers at 1.2.3.4 and 1.2.3.5. Each one has a few databases (catalogs), no overlap in database names.

<?php
$conn = mysql_connect('1.2.3.4', 'myuser', 'mypass');
mysql_select_db('some_db', $conn);
$conn2 = mysql_connect('1.2.3.5', 'myuser', 'mypass');

The above code will successfully connect to the 1.2.3.4 server and switch to the some_db database. But then the second mysql_connect() will fail with an "Unknown database 'some_db'" exception because the MySQL code is caching the last selected database name and sticking it on the end of the JDBC URL it uses to connect to the second database.

Notes
(0003371)
koreth   
08-29-08 14:37   
My hacky patch which probably breaks something else but at least makes the problem stop happening is to just comment out the line of code that records the database name:

--- a/modules/quercus/src/com/caucho/quercus/lib/db/Mysqli.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/db/Mysqli.java
@@ -922,7 +922,7 @@ public class Mysqli extends JdbcConnectionResource {
     try {
       if (isConnected()) {
         String catalog = dbname.toString();
- getEnv().getQuercus().setSpecial("mysql.catalog", catalog);
+ //getEnv().getQuercus().setSpecial("mysql.catalog", catalog);
        
         validateConnection().setCatalog(catalog);
(0003399)
nam   
09-05-08 15:59   
php/1457