2014-06-23 14:05 阅读 65

PHP PostgreSQL检查更新查询是否成功

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';
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dougua3706 dougua3706 2014-06-23 14:14

    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.

    点赞 评论 复制链接分享