Forum Moderators: coopster
$query="SELECT ........";
$result=musql_query($query);
if (!$result) //it doesn't work
do this;
if (mysql_num_rows($result)==0) //it works
do this;
In the labs of the university however it doesn't return a result at all
if (!$result) //it works
do this;
if (mysql_num_rows($result)==0)
{
/* returns: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource */
do this;
}
Which of these two is the normal?
If it is something that I can change from the .ini file, what exactly do i have to change?
Thanks in advance
if (!$result )
{
//do something with error
}else
{
if ( mysql_num_rows($result) <= 0 )
{
//do something else with this error
}
else
{
//do what you want
}
}
As far as anything with your php.ini file goes, wouldn't worry about changing anything if you change your program logic like my example above.
It works with your way but it seems that I will have to write the same things two times. It's weird!
Any other opinion?
if (!$result){
// um, your SQL is buggered up, or the
// database has crashed? Or maybe your
// connection is using the wrong password?
// $result should never look like this
}elseif (!mysql_num_rows($result)){
// $result is empty; no rows returned.
// this is an acceptable empty set.
// your SQL command is OK!
}else{
// you have data!
}
if you get this:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
That means your query returned nothing, and the problem occured while processing the database request. I often see:
1) no connection made to the database
2) database is not available
3) SQL query has bad syntax
4) SQL query uses a JOIN or GROUP or other
command that isn't supported
5) typo
IMHO, whenever you request *anything* from the database, you should always get *something* back. At least an empty set. If you get an empty set, that's OK, you can still do a mysql_num_rows() on an empty set. And if you get a bunch of rows, that's good. if you get NOTHING, that's bad. Unfortunately you often don't find out until you try to do a mysql_num_rows() on the result.
good luck