pdo插入mysql数据出错_php中通过pdo插入数据时,sql语句错误?
再次先謝謝各位大佬!!
接下來直接看代碼:
include 'mysql_ini.php';
$sql_select = "select * from word where word = ?";
$sql_inset = "insert into word(word,explain) values('ssss','sss')";
$word = 'passwor';
$explain = '密碼';
try{
$stmt_select = $pdo -> prepare($sql_select);
$stmt_select -> setFetchMode(PDO::FETCH_ASSOC);
$stmt_select -> execute(array($word));
$rows_select = $stmt_select -> fetchAll();
if($rows_select){
$error = '該單詞已存在!';
echo $error;
}else{
$stmt_insert = $pdo -> prepare($sql_inset);
$stmt_insert -> execute(array($word,$explain));
$rows_insert = $stmt_insert -> rowCount();
echo $rows_insert;
}
}catch(PDOException $e){
}
?>
如上代碼所示:$sql_inset變量中的SQL語句如果像上面那樣則無法插入數據,但如果去除指定列名(改為:insert into word values('ssss','sss')),則可以正確插入數據;
下面是我的表結構:
總結
以上是生活随笔為你收集整理的pdo插入mysql数据出错_php中通过pdo插入数据时,sql语句错误?的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: mysql重新载入my.cnf_怎么重新
- 下一篇: java每秒执行一次_Java性能权威指
