This can be done using the function mysql_affected_rows
which returns the number of lines actually affected in the last query using the 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, both the if($select)
or if(!$select)
as a mysql_errno()
would have the same impact if it were to verify whether such a query was executed, and if($select)
checks if the returned value has been executed (true) or not (false), mysql_errno()
returns the error number of the last operation, if it has failed, the same way it does the mysql_error()
but this returns the error as a numerical value.
For the compatibility problem 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 the documentation in Portuguese this warning is omitted, or why I do not know, but it practically says that functions like mysql_*
are obsolete, that is, the use of these functions is discouraged, from the PHP >= 5.5.0
and were completely removed from the PHP >= 7.0.0
.
Alternatively, there are the following extensions:
Some references:
What exactly is going wrong ? Everything seems to be in order here.
– Edilson
As I said just below @Edilson, as long as I type true fields, it returns a success message, although there is no such value.
– Jorge Felix
@Edilson, in relation to his answer, when taking the variable $select and using it in this way, it becomes Boolean, however, the mysql_affected_rows works as integer, and the $altera, comes as string, by chance would have to solve this problem?
– Jorge Felix
It was my error writing the syntax. I will now edit the answer.
– Edilson
Okay, now it should work. The indenter passed to this function should be the connection link
mysql_connect
. If not specified,mysql_affected_rows
automatically use the last connection to open.– Edilson