From:             
Operating system: Ubuntu 10.10
PHP version:      5.3SVN-2011-05-27 (SVN)
Package:          MySQL related
Bug Type:         Bug
Bug description:mysql_select_db fails changing host

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 bug report at http://bugs.php.net/bug.php?id=54941&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54941&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54941&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54941&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54941&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54941&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54941&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54941&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54941&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54941&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54941&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54941&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54941&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54941&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54941&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54941&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54941&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54941&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54941&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54941&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54941&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54941&r=mysqlcfg

Reply via email to