0

我正在尝试编写选择、连接和访问数据库的代码,但不工作: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;

请告诉我这段代码是否至少有意义

警告:mysql_select_db() 期望参数 2 是资源,字符串在第 16 行的 /home/glibet/public_html/api/api_storage.php 中给出

编辑[已解决]!

mysql_select_db($database[3], ${$makeconnection});
4

2 回答 2

2

它应该是

$makeconnection = $database[1];
${$makeconnection} = mysql_connect($database[0],$database[1],$database[2]);
mysql_select_db($database[3], ${$makeconnection});

并停止使用mysql_*其已弃用的 . 使用mysqliOR PDO

于 2013-03-16T05:29:04.340 回答
0

我认为您使连接过程有点复杂。可以通过以下方式更简单

$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;
于 2013-03-16T05:47:59.387 回答