note 103639 rejected from pdostatement.bindvalue by mazzanet

From: Date: Tue, 26 Apr 2011 10:22:37 +0000
Subject: note 103639 rejected from pdostatement.bindvalue by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179156@lists.php.net to get a copy of this message
Note Submitter: jakub dot lopuszanski at nasza-klasa dot pl ---- 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)); } ?>

« previous php.notes (#179156) next »