note 89323 modified in function.mysql-affected-rows by danbrown

From: Date: Tue, 03 Mar 2009 16:46:58 +0000
Subject: note 89323 modified in function.mysql-affected-rows by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151403@lists.php.net to get a copy of this message
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 --was-- 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 http://php.net/manual/en/function.mysql-affected-rows.php

« previous php.notes (#151403) next »