Edit report at http://bugs.php.net/bug.php?id=54941&edit=1
ID: 54941 Updated by: johan...@php.net Reported by: javier dot lanz at artica dot es Summary: mysql_select_db fails changing host -Status: Open +Status: Bogus Type: Bug Package: MySQL related Operating System: Ubuntu 10.10 PHP Version: 5.3SVN-2011-05-27 (SVN) Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php You should always pass the link identifier ($dbconnections[$key] in your case) as parameter. If that is not passed to mysql_* functions the last opened connection will be used. mysql_select_db() changes the defalt database used on the specified connection. Has nothing to do with multiple connections. Previous Comments: ------------------------------------------------------------------------ [2011-05-27 14:57:25] javier dot lanz at artica dot es Description: ------------ Hemos tenido un problema al intentar cambiar la conexión active entre dos bases de datos en distintos servidores para nuestro proyecto Pandora FMS. Hemos hecho un test muy simple para intentar acotar el problema, y hemos descubierto que está en "mysql_select_db" Creemos que puede ser porque las dos bases de datos se llaman igual, a pesar de estar en distintos servidores, pero no somos capaces de descubir por qué. Para más información pónganse en conctacto con nosotros. Hi there! We've had a problem trying to change the active connection between two databases hosted in two different servers meanwhile working into our Pandora FMS project. We've done a simple test trying to delimit the problem and we've discovered the problem is with "mysql_select_db" function. We think maybe the problem could be because these two databases have the same name although being in different servers, but we're not able to know why. If you need further information, please don't hesitate to contact me. Regards Javi & Miguel. Test script: --------------- <code><pre> <?php error_reporting(E_ALL); $dbs = array( 'miguel' => array('h' => '192.168.70.109', 'n' => 'pandora', 'p' => 'pandora', 'u' => 'root'), 'sergio' => array('h' => '192.168.70.123', 'n' => 'pandora', 'p' => '6683', 'u' => 'root') ); $dbconnections = array(); foreach ($dbs as $key => $db) { $result = mysql_connect ($db['h'], $db['u'], $db['p']); //var_dump($result); $dbconnections[$key] = $result; } var_dump($dbconnections); echo "---BY DEFAULT---\n"; var_dump(mysql_get_host_info()); echo "---CHANGING HOST---\n"; var_dump(mysql_select_db('pandora', $dbconnections['miguel'])); //Fail changing to miguel server var_dump(mysql_get_host_info()); //host info should display miguel's info, but sergio's is given echo "-----QUERY---\n"; $consulta = mysql_query('use pandora;'); $consulta = mysql_query('SELECT nombre FROM tagente;'); var_dump(mysql_error()); var_dump(mysql_fetch_array($consulta)); echo "-----ANOTHER QUERY---\n"; $consulta = mysql_query('use pandora;', $dbconnections['miguel']); $consulta = mysql_query('SELECT nombre FROM tagente;', $dbconnections['miguel']); var_dump(mysql_error($dbconnections['miguel'])); var_dump(mysql_fetch_array($consulta)); ?> </pre> </code> Expected result: ---------------- array(2) { ["miguel"]=> resource(2) of type (mysql link) ["sergio"]=> resource(3) of type (mysql link) } ---BY DEFAULT--- string(25) "192.168.70.123 via TCP/IP" ---CHANGING HOST--- bool(true) string(25) "192.168.70.109 via TCP/IP" -----QUERY--- string(0) "" array(2) { [0]=> string(7) "agente3" ["nombre"]=> string(7) "agente3" } -----ANOTHER QUERY--- string(0) "" array(2) { [0]=> string(15) "miguel-portatil" ["nombre"]=> string(15) "miguel-portatil" } Actual result: -------------- array(2) { ["miguel"]=> resource(2) of type (mysql link) ["sergio"]=> resource(3) of type (mysql link) } ---BY DEFAULT--- string(25) "192.168.70.123 via TCP/IP" ---CHANGING HOST--- bool(true) string(25) "192.168.70.123 via TCP/IP" -----QUERY--- string(0) "" array(2) { [0]=> string(7) "agente3" ["nombre"]=> string(7) "agente3" } -----ANOTHER QUERY--- string(0) "" array(2) { [0]=> string(15) "miguel-portatil" ["nombre"]=> string(15) "miguel-portatil" } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54941&edit=1