Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean giv

<?php
$conn = mysql_connect("localhost","root","");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
$sql = mysql_query("SELECT * FROM workers ORDER BY workerID DESC");
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
mysql_close($conn);
?>

我想了很久,,还不是不知道那出问题了

第1个回答  推荐于2016-03-03
连接后

应该是还没有选择库
$db_selected = mysql_select_db('库名称', $conn);

<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>本回答被提问者采纳

Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答