note 119935 added to pdostatement.bindvalue

From: Date: Fri, 23 Sep 2016 04:40:06 +0000
Subject: note 119935 added to pdostatement.bindvalue
Groups: php.notes 
Request: Send a blank email to php-notes+get-206655@lists.php.net to get a copy of this message
Be careful when trying to validate using PDO::PARAM_INT. Take this sample into account: <?php /* php --version * PHP 5.6.25 (cli) (built: Aug 24 2016 09:50:46) * Copyright (c) 1997-2016 The PHP Group * Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies */ $id = '1a'; $stm = $pdo->prepare('select * from author where id = :id'); $bind = $stm->bindValue(':id', $id, PDO::PARAM_INT); $stm->execute(); $authors = $stm->fetchAll(); var_dump($id); // string(2) var_dump($bind); // true var_dump((int)$id); // int(1) var_dump(is_int($id)); // false var_dump($authors); // the author id=1 =( // remember var_dump(1 == '1'); // true var_dump(1 === '1'); // false var_dump(1 === '1a'); // false var_dump(1 == '1a'); // true ?> My opinion: bindValue() should test is_int() internaly first of anything, It is a bug? I'm not sure. ---- Server IP: 72.52.91.14 Probable Submitter: 179.187.215.17 ---- Manual Page -- http://php.net/manual/en/pdostatement.bindvalue.php Edit -- https://master.php.net/note/edit/119935 Del: integrated -- https://master.php.net/note/delete/119935/integrated Del: useless -- https://master.php.net/note/delete/119935/useless Del: bad code -- https://master.php.net/note/delete/119935/bad+code Del: spam -- https://master.php.net/note/delete/119935/spam Del: non-english -- https://master.php.net/note/delete/119935/non-english Del: in docs -- https://master.php.net/note/delete/119935/in+docs Del: other reasons-- https://master.php.net/note/delete/119935 Reject -- https://master.php.net/note/reject/119935 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206655) next »