note 89323 added to function.mysql-affected-rows
| From: | dantebbs at tebbs dot org | Date: | Tue, 03 Mar 2009 16:43:57 +0000 |
| Subject: | note 89323 added to function.mysql-affected-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151402@lists.php.net to get a copy of this message | ||
A heads up for the use of this function. If you do:
$Result = mysql_query( $Command );
$RowsAffected = mysql_affected_rows( $Result );
then you will have a problem when using for example an UPDATE command. Whenever mysql_query(...)
returns true/false instead of a resource, then you would be attempting mysql_affected_rows( true )
which gives you $RowsAffected = false.
That may put a wrench in your works. :)
If you need to use/track the $Result handle, instead use:
$TempResult = mysql_query( $Command );
if ( $TempResult == false )
{
die( "Failed... : " . mysql_error() );
}
if ( is_resource( $TempResult ) == true )
{
$Result = $TempResult;
$NumRows = mysql_affected_rows( $Result );
}
else
{
$NumRows = mysql_affected_rows();
}
This is particularly useful inside a class which depends on the $Result handle.
-Dan
----
Server IP: 209.41.74.194
Probable Submitter: 206.124.146.116
----
Manual Page -- http://www.php.net/manual/en/function.mysql-affected-rows.php
Edit -- https://master.php.net/note/edit/89323
Del: integrated -- https://master.php.net/note/delete/89323/integrated
Del: useless -- https://master.php.net/note/delete/89323/useless
Del: bad code -- https://master.php.net/note/delete/89323/bad+code
Del: spam -- https://master.php.net/note/delete/89323/spam
Del: non-english -- https://master.php.net/note/delete/89323/non-english
Del: in docs -- https://master.php.net/note/delete/89323/in+docs
Del: other reasons-- https://master.php.net/note/delete/89323
Reject -- https://master.php.net/note/reject/89323
Search -- https://master.php.net/manage/user-notes.php