mysql执行中的php错误
好的,我有这个代码:mysql执行中的php错误,php,html,Php,Html,好的,我有这个代码: //this is the hi.php// <?php //highlight items// $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("juliver", $con); $result = mysql_query("SELECT * FROM hi W
//this is the hi.php//
<?php
//highlight items//
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("juliver", $con);
$result = mysql_query("SELECT * FROM hi WHERE pp='2'");
$hi = "";
while($row = mysql_fetch_array($result)) //<--- this is the line 13//
{
$hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700' rel='popup'><img src='".$row['name']."' />";
$hi .= "<p>".$row['title']."</p>";
$hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View full</a> </div>";
}
//Lots of lots of code here I just specified those code which in error.//
mysql_close($con);
//这是hi.php//
您的查询中可能有错误“从hi中选择*,其中pp='2'
尝试直接在mysql中执行该查询,看看会发生什么。确保表名和列拼写正确
另外,请尝试在backtick`字符中引用表名和列,以避免意外使用MySQL保留字。$result
有一个布尔值-可能是因为查询失败
在尝试使用之前,您应该验证结果
查询完成后,您可以执行以下操作来查看查询失败的原因:
if(!$result)
exit(mysql_error());
“SELECT*FROM hi WHERE pp='2'”查询可能返回false,这意味着没有可完全填充查询的记录。请尝试echo mysql_num_rows($result);为了知道查询返回的行数。或者更简单地说,您可以使用
$result=mysql\u查询(“选择*从hi WHERE pp='2'”)或死(mysql\u error())代码>检查以下内容:
mysql_connect("localhost","username","password");
首先,您应该在代码中使用适当的异常处理。排队后
$result = mysql_query("SELECT * FROM hi WHERE pp='2'");
您应该检查它是否返回了资源id,或者是否有任何错误
if(!$result){
// if you use try-catch, then use
throw new Exception(mysql_error());
// Or you can use
die(mysql_error());
}else{
while($row = mysql_fetch_array($result)) //<--- this is the line 13//
{
$hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700' rel='popup'><img src='".$row['name']."' />";
$hi .= "<p>".$row['title']."</p>";
$hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View full</a> </div>";
}
}
if(!$result){
//如果你使用try-catch,那么使用
抛出新异常(mysql_error());
//或者你可以使用
die(mysql_error());
}否则{
while($row=mysql\u fetch\u array($result))//提示:始终搜索准确的错误消息。您将找到大量结果:echo mysql\u error()
可以帮助解决大多数问题。请在mysql\u查询(…)下执行此操作
。他应该总是向浏览器抛出异常或一般错误消息。如果没有结果,mysql\u query
将返回一个空的resultset,而不是false
。但是变量的值将为false,因为queryNo中有空resultset。空resultset是mysql资源类型。它不是布尔值false
.mysql\u query
仅在查询出错且无法执行时返回布尔值false
。如果未建立连接,它将退出代码,并出现错误“'cannot connect:”。。。。
if(!$result){
// if you use try-catch, then use
throw new Exception(mysql_error());
// Or you can use
die(mysql_error());
}else{
while($row = mysql_fetch_array($result)) //<--- this is the line 13//
{
$hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700' rel='popup'><img src='".$row['name']."' />";
$hi .= "<p>".$row['title']."</p>";
$hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View full</a> </div>";
}
}