php mysql准备语句问题

标签 php mysql prepared-statement

我从 mysql 准备好的语句开始,由于我不理解的错误,我无法前进。这是我更新 de db 的函数:

public function updateUserData($user_label,$user_alliance, $score, $rank, $timestamp, $user_id, $db_object){


    $sql='UPDATE users SET label = ?, alliance = ?,  points = ?, position = ?, modified = ?,  WHERE user_id = ?';

    $label = $user_label;
    $alliance = $user_alliance;
    $points = $score;
    $position = $rank;
    $modified = $timestamp;
    $user_id_q = $user_id;

    $stmt = $db_object->prepare($sql);
    if($stmt === false) {
      trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $db_object->error, E_USER_ERROR);
    }

    $stmt->bind_param('ssiiii',$label,$alliance,$points,$position,$modified,$user_id_q);

    /* Execute statement */
    $stmt->execute();

    echo $stmt->affected_rows;

    $stmt->close();

}

下面是我的使用方法:

//Get user Data
$user = new user();
$page_clasif = $user->getPagClasif($ch,$url_clasif);
$user_label = $user->findPlayerName($page_clasif);
$user_alliance = $user->findAllianceName($page_clasif);
$rank = $user->findRank($page_clasif);
$score = $user->findScore($page_clasif);
$user_id = $user->findPlayerId($page_clasif);
$version = $user->findVersion($page_clasif);
$user_universe = $user->findUniverse($page_clasif);

//Get install date as timestamp
$core = new core();
$timestamp = $core->dateAsTimestamp();
//Update User
$user->updateUserData($user_label,$user_alliance,$score,$rank,$timestamp,$user_id,$conn);

这是错误:

 PHP Fatal error:  Wrong SQL: UPDATE users SET label = ?, alliance = ?,  points = ?, position = ?, modified = ?,  WHERE user_id = ? Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id = ?'

有什么想法吗? 提前致谢。

最佳答案

WHERE 关键字前有一个多余的逗号:

$sql='UPDATE users SET label = ?, alliance = ?,  points = ?, position = ?, modified = ?,  WHERE user_id = ?';
//                                                                 remove this comma --^

关于php mysql准备语句问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20999002/

相关文章:

MySQL : named parameters with PREPARE command?

php - 了解 PDO/Prepared Statements 如何与多种数据库类型配合使用

MySql "view"、 "prepared statement"和 "Prepared statement needs to be re-prepared"

php - 只定义一次 PHP 常量

java - SQLException w/Tomcat 7.0 JDBC 连接池和 MySql

mysql - 如何在映射表中显示用户的名称而不是 ID?

java - MySQL Java 使用 JComboBox 设置第二个 JComboBox

c# - 在 MySQL 中加密,在 C# 中解密

javascript - AngularJs 1.3 $resource 忽略一些字符

php - Stack Overflow URL 是如何工作的?