0

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. 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();
}
1
  • As you said the problem lies in the resource hungry codes preceding it. The issue can be accurately tackled only after seeing those sections of the code. Commented Jan 11, 2012 at 12:18

3 Answers 3

2

or die(mysql_error()) should be added after the query is executed:

$query="SELECT * FROM user";
$result=mysql_query($query) or die(mysql_error());

Also, the else will never execute because you die() before that.

I suggest this:

$query="SELECT * FROM user";
$result=mysql_query($query);

if($result)
{
    success($result);
}
else //error
{
    failure(mysql_error());
}
Sign up to request clarification or add additional context in comments.

Comments

0

You are using or with string.

$query="SELECT * FROM user";
$result=mysql_query($query);

if($result)
{
    success();
}
else //error
{
    failure();
}

Comments

0

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.

Second, to see if your query returned any rows, use mysql_num_rows($result) > 0.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.