php下的mysql_fetch_object()不能使用问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 17:21:49
做了几个PHP页,总显示如下错误:
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in E:\PHP\use\read.php on line 7
原代码为:
<?
$handler=mysql_pconnect("localhost","root","");
mysql_select_db("php_user",$handler);

$query="select comment,authname,authmail,posttime,msg from msgboard order by msgid edsc";
$result=mysql_query($query,$handler);
while($row=mysql_fetch_object($result)){
if(!empty($row->authmail)){
echo "<a href='mailto:".$row->authmail."'>".$row->authname."</a>在".$row->posttime."的留言是:<br>";
}else{
echo $row->authname."在".$row->posttime."的留言是:<br>";
}
echo $row->msg;
echo "<br><hr width=80%><br>";
}
?>

$query="select comment,authname,authmail,posttime,msg from msgboard order by msgid edsc";

看看你的这一句sql的最后,你写成了edsc,应该是desc。一般来说你的出错信息却说它不是一个资源,那就证明,你读取有误,或者你的sql查询有误。规范的代码应该这样写:

$result=mysql_query($query,$handler);
if($result==false)
{
echo("数据库查询错误");
exit(0);
}
这样错了自己马上就知道了。