-2

嗨,我正在使用 PDO 包装对象

 https://github.com/Xeoncross/DByte/blob/master/example.php

更新功能有一些问题。这是他们定义的更新功能

static function update($table, $data, $value, $column)
{
    $keys = implode('`=?,`', array_keys($data));
    if($statement = DB::query(
        "UPDATE`$table`SET`$keys`=? WHERE`$column`=?",
        array_values($data + array($value))
    ))
        return $statement->rowCount();
}

我要更新的功能

public function update_users($user_id, $user_name, $user_email, $user_role, $user_phone){

        $user_data = array(
        'user_name' => $user_name,
        'user_email' => $user_email,
        'user_pass' => $user_pass,
        'user_role' => $user_role,
        'user_phone' => $user_phone,
        );


        $result = DB::update('users', $user_data, $user_id);



}

这不起作用我得到的错误是,

 Warning: Missing argument 4 for DB::update(), called in \XXXClass.php on line 47 and defined in XXXX\Application\inc\DB.php on line 120
4

1 回答 1

0

您需要传入列名(方法的第四个参数):

$result = DB::update('users', $user_data, $user_id, 'user_id'); // I presume `user_id` is the name of that column

在 SQL 关键字和列/表名之间放置空格也没有什么坏处:

"UPDATE `$table` SET `$keys`=? WHERE `$column`=?"
于 2013-09-11T17:36:45.983 回答