[英]PHP mysql query not producing result
I have a problem with the below query not producing a result. 我有一个问题,以下查询不生成结果。 There is nothing wrong with the query.
查询没有任何问题。 But it is being run after a lot of other time and memory consuming instructions within a PHP script.
但它是在PHP脚本中经过许多其他时间和内存消耗指令后运行的。 If I restrict the number of operations performed in the script before this query is executed, it works.
如果我在执行此查询之前限制脚本中执行的操作数,则它可以正常工作。
How do I find out what the problem is? 我如何找出问题所在? Is there a way to be notified if the script exceeds memory or execution time limitations?
如果脚本超出内存或执行时间限制,是否有通知的方法? Or could there be another reason?
或者还有其他原因吗?
$query="SELECT * FROM user" or die(mysql_error());
$result=mysql_query($query);
if($result)
{
success();
}
else //error
{
failure();
}
or die(mysql_error())
should be added after the query is executed: 执行查询后应添加
or die(mysql_error())
:
$query="SELECT * FROM user";
$result=mysql_query($query) or die(mysql_error());
Also, the else will never execute because you die()
before that. 此外,else永远不会执行因为你之前
die()
。
I suggest this: 我建议这个:
$query="SELECT * FROM user";
$result=mysql_query($query);
if($result)
{
success($result);
}
else //error
{
failure(mysql_error());
}
You are using or
with string. 您正在使用
or
使用字符串。
$query="SELECT * FROM user";
$result=mysql_query($query);
if($result)
{
success();
}
else //error
{
failure();
}
First of all, you can always check if there is a mysql error by using mysql_error()
which returns the mysql error string if it exists. 首先,您可以使用
mysql_error()
来检查是否存在mysql错误,如果mysql错误字符串存在,则返回该错误字符串。
Second, to see if your query returned any rows, use mysql_num_rows($result) > 0
. 其次,要查看您的查询是否返回任何行,请使用
mysql_num_rows($result) > 0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.