<lkrubner@geocities.com> wrote in message
news:1102567588.839277.20340@c13g2000cwb.googlegro ups.com...[color=blue]
>
>
>
www.php.net says:[color=green][color=darkred]
> >>>>>>>>>>>>[/color][/color]
> Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query()
> returns a resource identifier or FALSE if the query was not executed
> correctly. For other type of SQL statements, mysql_query() returns TRUE
> on success and FALSE on error. A non-FALSE return value means that the
> query was legal and could be executed by the server. It does not
> indicate anything about the number of rows affected or returned. It is
> perfectly possible for a query to succeed but affect no rows or return
> no rows.[color=green][color=darkred]
> >>>>>>>>>>>>>[/color][/color]
>
> So if zero rows come back the function will still return true? It only
> returns false if something much more serious happened? My script below
> is failing somewhere and I'm trying to trouble shoot.
>
>[/color]
The errors that MySQL returns has nothing to do with what rows and how many
rows are returned. If 'mysql_errno()' returns 0 there was no problem
performing the query (no problems with the query syntax). If it returns
other than 0 then there was. You must use 'mysql_num_rows' or
'mysql_affected_rows':
http://us2.php.net/manual/en/functio...l-num-rows.php
"mysql_num_rows() returns the number of rows in a result set. This command
is only valid for SELECT statements. To retrieve the number of rows affected
by a INSERT, UPDATE or DELETE query, use mysql_affected_rows()."
You should always do something like so:
....
$result = mysql_query($query,$database);
if ((mysql_errno($database) > 0)
{
// query error - do stuff here
}
else
{
// query good - check for results
$num_results = mysql_num_results($database);
if ($num_results == 0)
{
// no results returned - do stuff here
}
else
{
// there are results - do stuff here
}
}
....
Basic, I know but you should get the idea. If you are programming for the
web then you'll see you're errors on the web pages. If you want you can
create a log for informational purposes... try this:
// set these lines at the start (top) of your script
define('LOGFILE',true); // set to false to turn off logging.
$u_id = uniqid('uid');
define('UID',$u_id);
function logfile($txt)
{
if (LOGFILE)
{
$txt = date("G:i:s - ").UID.' - '.$txt.chr(13);
$lf = 'path\\to\\logfile'.date(' D M j - Y').'.txt';
$fp = fopen($lf,'a');
fwrite($fp,$txt,1024);
fclose($fp);
}
}
// ---
then try:
logfile("\n\r--- start of request ---");
....
$result = mysql_query($query,$database);
if ((mysql_errno($database) > 0)
{
// query error - do stuff here
logfile('MySQL: There was an error with the query ->
'.mysql_errno($database).': '.mysql_error($database));
}
else
{
// query good - check for results
$num_results = mysql_num_results($database);
logfile('INFO: Query has been run.');
if ($num_results == 0)
{
// no results returned - do stuff here
logfile('INFO: No results found from query,');
logfile("QUERY: $query");
// by logging the query you can check your values
}
else
{
// there are results - do stuff here
logfile("INFO: Results found -> $num_results");
}
}
....
Norman
---
Avatar Hosting at
www.easyavatar.com