|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-05-27 15:21 UTC] johannes@php.net
-Status: Open
+Status: Bogus
[2011-05-27 15:21 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
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" }