php查询mysql mysql_fetch_row取值为空

2024-11-06 18:19:01
推荐回答(2个)
回答1:

上完整代码~

参考:
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "
";
}

mysql_close($con);
?>

mysql_query 后要 mysql_fetch_array,得到数组才可以。

回答2:

没看到连接数据库