I m trying to write a code of choose, connecting and accessing database but isn't working :X
$mysql_storage = true;
if($mysql_storage){
$databases = array(
array("localhost","glibet_login","#####","glibet_site")
);
foreach($databases as $database){
$makeconnection = $database[1];
${$makeconnection} = mysql_connect($database[0],$database[1],$database[2]);
mysql_select_db($database[3], $database[1]);
}
}
$query = "SELECT * FROM users WHERE email='marsalcorreialima@gmail.com'";
$littlequery = mysql_query($query, $glibet_login);
$littlefetch = mysql_num_rows($littlequery);
print $littlefetch;
Please tell me if this code at least makes sense
Warning: mysql_select_db() expects parameter 2 to be resource, string given in /home/glibet/public_html/api/api_storage.php on line 16
EDIT [SOLVED]!
mysql_select_db($database[3], ${$makeconnection});
it should be
$makeconnection = $database[1];
${$makeconnection} = mysql_connect($database[0],$database[1],$database[2]);
mysql_select_db($database[3], ${$makeconnection});
And stop using mysql_*
its deprecated . use mysqli
OR PDO
.
I think you have made the connection process a little complicated. It could have been more simple in the following way
$mysql_storage = true;
$makeconnection;
if($mysql_storage){
$makeconnection = mysql_connect("localhost","glibet_login","#####");
mysql_select_db("glibet_site", $makeconnection);
}
$query = "SELECT * FROM users WHERE email='marsalcorreialima@gmail.com'";
$littlequery = mysql_query($query, $makeconnection);
$littlefetch = mysql_num_rows($littlequery);
print $littlefetch;