当使用阵列来传递数据,该数据被作为字符串传递:
从docs:
值的数组与尽可能多的元件,因为在结合的参数正在执行的SQL语句。所有值都被视为PDO :: PARAM_STR。
但是,当您手动输入1
直接将查询作为int处理时。让我看看是否可以进一步挖掘一下,看看当一个字符串被转换为一个int时,内部发生了什么。
编辑:这可能是已经提交并接受most similar bugs之一:
1)
SET @a = 1;
SELECT @a;
2)
SET @a = 1.1;
SELECT @a;
.. and this
3)
SET @a = 1.1;
SELECT @a + 7;
returns '8.100000000000000000000000000000'
(probably the addition will convert "1.1" to a double, the result
of the addition is also a DOUBLE and finally the DOUBLE is converted
to a string - that should be OK as well as far as I can understand)
所以看起来在内部,当你把它传递一个int MySQL是转换为双。这将很好地解释你所看到的行为。
这是其他同类(数字并不完全正确)的列表错误你可能感兴趣的:
http://bugs.mysql.com/bug.php?id=46037
http://bugs.mysql.com/bug.php?id=35071
http://bugs.mysql.com/bug.php?id=35071 < - 好一个展示Win和林之间的差异
和filtered list of data type bugs我仔细阅读了哪些有趣的阅读。
编辑2:啊!
这里是一个bug that rather perfectly说明您的问题:
Reproduce code:
---------------
CREATE TABLE my_db.my_table (
id int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
<?php
$DB = new PDO('mysql:dbname=my_db;host=localhost', 'user', 'pass');
$stmt = $DB->prepare('select * from my_table where id>?');
$stmt->bindValue(1, 13);
$stmt->execute();
?>
or
<?php
$DB = new PDO('mysql:dbname=my_db;host=localhost', 'user', 'pass');
$stmt = $DB->prepare('select * from my_table where id>?');
$stmt->execute(array(13));
?>
Expected result:
----------------
select * from my_table where id>13
Actual result:
--------------
select * from my_table where id>'13'
什么是 “落后” $ DB?一个sqlite,MySQL,postgresql,???连接? – VolkerK
MySQL,它是PDO的包装。 – PPPHP