how to receive a connection failure if the update is not successful?

Asked

Viewed 32 times

0

Let’s say I have an update button in the bank.

$query = mysql_query("UPDATE $tabela set algo='$algo' WHERE id=1);

if ($query) {
    echo "sucesso";
} else {
    echo 'falha';
}

to check if the query was registered in the database successfully (if there was no error in connection (eg: connection crashed) or if there was an error in the update) I do the above procedure?

  • This already solves the problem. Or has some other problem, besides using obsolete functions.

1 answer

0

With the mysql_affected_rows you can see how many records were affected.
If zero, update failed.

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Não foi possível conectar: ' . mysql_error());
}
mysql_select_db('mydb');

/* Atualiza os registros */
mysql_query("UPDATE mytable SET used=1 WHERE id < 10");
printf ("Registros atualizados: %d\n", mysql_affected_rows());
mysql_query("COMMIT");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.