始终从pdo更新查询获得错误响应

时间:2017-03-06 12:15:30

标签: php

我试图更新我的数据库,但无论何时我喜欢这个

if($query){
echo 'executed';
}
else {
echo 'error';
}

我面临的问题是查询是否成功更新数据库但导致错误响应这里是我的代码

 public static function updateItem($slug, $title, $description, $thumbnail, $preview, $main_file, $screenshot, $category, $amount, $review, $demo_url, $tags, $live, $video, $apc) {
        $db = new Database;
        $main_category = Login::encrypt_decrypt("decrypt", $apc);
        $sub_category = Login::encrypt_decrypt("decrypt", $category);
        $q = $db->updateRow("UPDATE items SET name = ?, description = ?, thumbnail = ?, main_file = ?, categories = ?, sub_category = ?, demo_url = ?, slug = ?, price = ?, reviewer_comment = ?, datetime = ?, status = ?, video_file = ?, item_tags_string = ?, preview_file = ?, screenshot_file = ?, live_file = ? WHERE user_id = ? AND temp_files != '' AND temp_file_real != '' AND status = ?", [$title, $description, $thumbnail, $main_file, $main_category, $sub_category, $demo_url, $slug, $amount, $review, Item::nowTime(), 'queue', $video, $tags, $preview, $screenshot, $live, Profile::getid(), 'temp']);
        if($q){
            echo 'good'; exit;
        }
        else {
            echo 'wrong'; exit;
        }
    }

这是我的数据库连接代码

public function __construct($username = "root", $password = "", $host = "localhost", $dbname = "market", $options = []) {
        $this->isConn = TRUE;
        try {
            $this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
            $this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        } catch (PDOException $e) {
            throw new Exception($e->getMessage());
        }
    }

这里是更新查询功能

public function updateRow($query, $params = []) {
        $this->insertRow($query, $params);
    }

public function insertRow($query, $params = []) {
        try {
            $stmt = $this->datab->prepare($query);
            $stmt->execute($params);
            return TRUE;
        } catch (PDOException $e) {
            throw new Exception($e->getMessage());
        }
    }

任何人都可以告诉我为什么我总是收到错误陈述

1 个答案:

答案 0 :(得分:2)

您的updateRow功能不会返回任何内容,因此' $ q'是空的。

public function updateRow($query, $params = []) {
    return $this->insertRow($query, $params);
}