我正在尝试使PDO MYSQL语句只插入数据库中不存在的数据
PHP的简单示例
$sql = INSERT INTO mytable SET hash=:hash, tablename=:tablename, recuid=:recuid WHERE recuid NOT IN (SELECT recuid FROM mytable);
$insert = $this->_pdo->prepare($sql);
$insert->execute(array(
':hash' => $this->_getHash,
':tablename' => $this->_catNewTable,
':recuid' => $result->uid
));
this->_pdo
连接到工作正常的数据库this->_getHash
生成随机哈希码var_dump结果:
string(185) "INSERT INTO sys_refindex SET hash=:hash, tablename=:tablename, recuid=:recuid WHERE recuid NOT IN (SELECT recuid FROM sys_refindex)"
Syntax error or access violation: 1064 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 recuid NOT IN (SELECT recuid FROM sys_refindex)' at line 1SQLSTATE[42000]
如果认为WHERE语句与占位符结合存在问题?