我遇到问题mysql_select_db()
函数未选择正确的数据库。我的代码如下:
global $file_count;
$conlivedata = mysql_pconnect("localhost","*****","*****");
if (!$conlivedata) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$con = mysql_pconnect("***************","*****","*****");
if (!$con) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_select_db("csv_db", $con)or die("A MySQL error has occurred.Your Query: Error: (" . mysql_errno() . ") " . mysql_error());
$result = mysql_query("SELECT * FROM `tbl_name` WHERE EmailAddr <> ' ' ORDER BY `EmailAddr`") or die("<br/>A MySQL Query error has occurred.Your Query: Error: (" . mysql_errno() . ") " . mysql_error());
while($row = mysql_fetch_array($result))
{
echo $row['first_name'] . " " . $row['last_name'];
$Email = $row['EmailAddr'];
if ($Email != NULL ){
mysql_select_db("foswood_db", $conlivedata) or die("<br/>A MySQL error has occurred Slecting Database.<br />Your Query: <br/> Error: (" . mysql_errno() . ") " . mysql_error());
$liveresult = mysql_query("SELECT COUNT(*) FROM pledges WHERE EmailAddr = '$Email'") or die("<br/>A MySQL error has occurred.<br />Your Query: <br /> Error: (" . mysql_errno() . ") " . mysql_error());
if(mysql_result($liveresult, 0) ) echo ': **Voted**';;
mysql_select_db("csv_db", $con) or die("<br/>A MySQL error has occurred Slecting Database.<br />Your Query: <br /> Error: (" . mysql_errno() . ") " . mysql_error());
}
echo "<br />";
}
mysql_close($con);
mysql_close($conlivedata);
我收到错误消息:
A MySQL error has occurred.
Your Query:
Error: (1146) Table 'csv_db.pledges' doesn't exist
有谁知道为什么请?
答案 0 :(得分:1)
您应该指定用于查询的数据库。
$result = mysql_query("SELECT * FROM `tbl_name` WHERE EmailAddr <> ' ' ORDER BY `EmailAddr`", **$con**) ...