I have a problem with connections to mysql currently from a PHP I establish connections to mysql in the following way
<?php
$date = strftime( "%Y-%m-%d %H:%M:%S"); //FECHA
function conectarse($host,$usuario,$password,$BBDD){
$link=@mysql_connect($host,$usuario,$password) or die (mysql_error());
mysql_select_db($BBDD,$link) or die (mysql_error());
return $link;
}
$link=conectarse("localhost","usuario1","123456","basededatos");
$con_at = "select * from tabla";
$con_at = mysql_query($con_at,$link);
$con = mysql_fetch_array($con_at);
$atdb_server = $con['at_dbserver'];
$atdb_user = $con['at_dbuser'];
$atdb_pass = $con['at_dbpass'];
function conectarse2($host,$usuario,$password,$BBDD){
$link2=@mysql_connect($host,$usuario,$password) or die ('error 2da db');
mysql_select_db($BBDD,$link2) or die (mysql_error());
return $link2;
}
$link2=conectarse2($atdb_server,$atdb_user, $atdb_pass,"base2");
$sql = "SELECT * FROM config_camp where cp_tipo = '0' ";
$data =mysql_query($sql, $link);
$afectadas = mysql_num_rows(mysql_query($sql, $link));
The problem is that the query ($ sql) does not work, (it does it towards the first connection). But if I delete the second connection if it works. I need to keep both connections since later I have to make queries to both. Does anyone have any idea how to do it? Hope it's understandable. Thanks in advance.