note 103639 added to pdostatement.bindvalue
| From: | jakub dot lopuszanski at nasza-klasa dot pl | Date: | Mon, 25 Apr 2011 20:18:01 +0000 |
| Subject: | note 103639 added to pdostatement.bindvalue | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179126@lists.php.net to get a copy of this message | ||
even if you $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); be aware that bindValue
(at least with MySQL driver) will not help you detect any type errors, duplicated calls, or binding
to wrong parameter.
Bellow is a part of my PHPUnit tests that confirm this:
<?php
public function testBindValueAlwaysReturnsTrue(){
$s = $this->getSUT("SELECT 1 FROM users WHERE id=:id");
//this one is ok:
$this->assertSame(true,$s->bindValue(':id',1,PDO::PARAM_INT));
//this one is not ok at all, as '1' is not integer.
//moreover we already bound id
$this->assertSame(true,$s->bindValue(':id','1',PDO::PARAM_INT));
//this is also bad to allow both :id and id
$this->assertSame(true,$s->bindValue('id',1,PDO::PARAM_INT));
//1 is not a string
$this->assertSame(true,$s->bindValue('id',1,PDO::PARAM_STR));
//'a' is not an integer
$this->assertSame(true,$s->bindValue('id','a',PDO::PARAM_INT));
//null is surely not an integer:
$this->assertSame(true,$s->bindValue('id',null,PDO::PARAM_INT));
//1 is not a null
$this->assertSame(true,$s->bindValue('id',1,PDO::PARAM_NULL));
//13 is not a valid type of parameter
$this->assertSame(true,$s->bindValue(':id',1,13));
//'atlantis' is not even mentioned in the SQL query string:
$this->assertSame(true,$s->bindValue(':atlantis',1,PDO::PARAM_INT));
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.190.218.49
----
Manual Page -- http://www.php.net/manual/en/pdostatement.bindvalue.php
Edit -- https://master.php.net/note/edit/103639
Del: integrated -- https://master.php.net/note/delete/103639/integrated
Del: useless -- https://master.php.net/note/delete/103639/useless
Del: bad code -- https://master.php.net/note/delete/103639/bad+code
Del: spam -- https://master.php.net/note/delete/103639/spam
Del: non-english -- https://master.php.net/note/delete/103639/non-english
Del: in docs -- https://master.php.net/note/delete/103639/in+docs
Del: other reasons-- https://master.php.net/note/delete/103639
Reject -- https://master.php.net/note/reject/103639
Search -- https://master.php.net/manage/user-notes.php