为什么以下语句在 php 中失败(我已经建立了到名为 config.db 的 sqlite 数据库的 PDO 连接)。
$stmt = $this->db->prepare("INSERT INTO config (S_BASE_DIR) VALUES (':col0')");
$stmt->bindParam(':col0',$colValue);
$stmt->execute();
$stmt->close();
确切的错误是:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 25 bind or column index out of range'
最佳答案
绑定(bind)到列时,不需要引用该列:
$stmt = $this->db->prepare( "INSERT INTO config (S_BASE_DIR) VALUES ( :col0 )" );
$stmt->bindParam(':col0', $colValue);
用引号引起来的 :col0
它只是一个字符串,而不是绑定(bind)参数。
关于php - SQlite 3 PDO 语句在 PHP 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588043/