码迷,mamicode.com
首页 > 数据库 > 详细

mysql中PDO参数化引号引起的Warning: PDOStatement::execute(): SQLSTATE[HY093]:报错

时间:2015-10-17 16:11:09      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

sql语句之前是这样写的:INSERT INTO tablename SET a = ‘:a‘,b = ‘:b‘,c = ‘:c‘,d = :d,e = :e

 

$data = array

(
[‘:a‘] => 1,
[‘:b‘] => 2,
[‘:c‘] => 3,
[‘:d‘] => 4,
[‘:e‘] => 5,
)

$prepareResualt = $pdo->prepare($sql);
$prepareResualt->execute($data);

 

出现了Warning:  PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens报错

 

然后改成:INSERT INTO tablename SET a = :a,b = :b,c = :c,d = :d,e = :e

 

正常插入数据 ,大概是参数化语句中不需要把字符串类型的参数加上引号吧,也确实感觉有点多此一举。

mysql中PDO参数化引号引起的Warning: PDOStatement::execute(): SQLSTATE[HY093]:报错

标签:

原文地址:http://www.cnblogs.com/yuanfeiblog/p/4887511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!