|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-05-02 07:31 UTC] frozenfire@php.net
[2011-05-05 08:17 UTC] jakub dot lopuszanski at nasza-klasa dot pl
[2011-05-26 14:42 UTC] johannes@php.net
[2011-07-02 04:09 UTC] frozenfire@php.net
-Status: Open
+Status: No Feedback
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 06:00:02 2025 UTC |
Description: ------------ even if you $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); the function bindValue (at least with MySQL driver) will not help you detect any type errors, duplicated calls, or binding to wrong parameter. Test script: --------------- Bellow is a part of my PHPUnit tests that confirm this ( i guess you can figure out that getSUT, gets system under tests, that is prepares a query from PDO object connected to MySQL database): <?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)); } ?> Expected result: ---------------- I would expect either more precise documentation which would list all cases for which bindValue returns false (I could not find any), or fixing the function, to return false in cases mentioned above. Actual result: -------------- function returns true whatever I do.