note 89323 deleted from function.mysql-affected-rows by danbrown

From: Date: Tue, 28 Apr 2009 01:47:40 +0000
Subject: note 89323 deleted from function.mysql-affected-rows by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153871@lists.php.net to get a copy of this message
Note Submitter: dantebbs at tebbs dot org ---- A heads up for the use of this function. If you do: <?php $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: <?php $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

« previous php.notes (#153871) next »