I'm using a PSQL database with PHP to do an update query. I have to check if the query was successful or not. I tried the MySQL 'version' like this but it doesn't work and I always get the echo 'error';
:
public function update_user($psql, $data) {
$update = pg_fetch_all(pg_query_params($psql, "UPDATE users SET first_name = $1, last_name = $2, email = $3 WHERE id = $4", array($data['first_name'], $data['last_name'], $data['email'], $data['user_id'])));
if ($update) {
echo 'succes';
}
else {
echo 'error';
}
}
pg_query_params
returns a value described as:
A query result resource on success or FALSE on failure.
So just check that return value for falseness.
Also since your update query does not return any row, even when it succeeds there's no point in passing its return value to pg_fetch_all
. Not being false
is all that matters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.