2012-09-25 44 views
1

爲什麼下面的語句在php中失敗(我建立了一個到名爲config.db的sqlite數據庫的已建立的PDO連接)。SQlite 3 PDO語句在PHP中失敗

$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'

回答

2

當綁定到列,你並不需要引用列:

$stmt = $this->db->prepare("INSERT INTO config (S_BASE_DIR) VALUES (:col0)"); 
$stmt->bindParam(':col0', $colValue); 

隨着:col0引號包圍它僅僅是一個字符串,而不是綁定參數。