This can be done by using the mysql_affected_rows
function that returns the number of rows actually affected in the last query using UPDATE
.
$altera = "UPDATE z SET y= a WHERE x= x";
$select = mysql_query($altera);
if($select){
if(mysql_affected_rows() > 0){
print "foram atualizadas (". mysql_affected_rows() .") linhas";
} else {
print "consulta efetuada, mas nenhuma linha modificada";
}
}else{
die("Erro: " . mysql_error());
}
Regardless of what you want, either
if($select)
or
if(!$select)
as a
mysql_errno()
would have the same impact if it were to verify that this query was executed, with
if($select)
checking if the returned value was executed ( true ) or ( false ) ,
mysql_errno()
returns the error number of the last operation, if it has failed, just as it does
mysql_error()
but this returns the error as a numeric value.
For the problem of compatibility with even lower versions, there is the function mysql_numrows()
(also discontinued) .
Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension
should be used. See also MySQL: choosing an API guide and related FAQ
for more information.
In Portuguese documentation this warning is omitted, why I do not know, but it pretty much says mysql_*
functions are obsolete , that is, the use of these functions is discouraged from PHP >= 5.5.0
and have been completely removed from PHP >= 7.0.0
.
Alternatively, the following extensions exist:
Some references: