What role does the third parameter in PDOStatement::bindValue play?

WBOY
Release: 2016-09-19 08:51:55
Original
1088 people have browsed it

有这样一个表:
What role does the third parameter in PDOStatement::bindValue play?

username字段是varchar(20)。
查询是这样的:

<code>$conn = new PDO(...);
$sql = "select * from user where username=:username";
$username=123;
$stmt=$conn->prepare($sql);
$stmt->bindValue(":username", $username, PDO::PARAM_STR);
$stmt->execute();
print_r($stmt->fetchAll());</code>
Copy after login

我知道这里的$username其实写错了,应该是'123',不过因为下边又把参数指定成PDO::PARAM_STR了所以查询到了2620这条。
但是当我突发奇想把PDO::PARAM_STR 改成PDO::PARAM_INT的时候,结果却是2620、2621两条都被查询出来了。
这个结果我十分不理解,那么这个PDO::PARAM_XXX到底做了什么?求明白的帮我解释一下,谢了。
好吧,敲完这个问题之后我直接在数据库里试了下select * from user where username=123,结果也是两条都出来,那就不是PDO的问题了,但是还是不明白为什么123不加引号会有这样的结果。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template