note 101695 added to pdostatement.bindvalue
| From: | schindhelm at gmail dot com | Date: | Wed, 05 Jan 2011 19:34:07 +0000 |
| Subject: | note 101695 added to pdostatement.bindvalue | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175465@lists.php.net to get a copy of this message | ||
nicemandan: I altered your method to check if there was a data type specified. If not, will use a
default data type (string). Saves time, space & doesn't bring up php errors.
<?php
class MyPDOStatement extends PDOStatement
{
// expect strings to be the default data values
const DEF_PARAM_TYPE = PDO::PARAM_STR;
protected function __construct() {}
private function bindArray(&$statement, &$paramArray) {
foreach ($paramArray as $k=>$v) {
if (is_array($v)) @$statement->bindValue($k, $v[0], $v[1]);
else @$statement->bindValue($k, $v, self::DEF_PARAM_TYPE);
}
}
}
$statement = "INSERT INTO db.users (id, firstName, lastName, age) VALUES(:id, :firstName,
:lastName, :age)";
$values = array(
':id' => PDO::PARAM_NULL,
':firstName' => 'Foo',
':lastName' => 'Bar',
':age' => array('18', PDO::PARAM_INT)
);
$statement->bindArray($statement, $values);
?>
----
Server IP: 85.214.154.209
Probable Submitter: 188.99.35.137
----
Manual Page -- http://www.php.net/manual/en/pdostatement.bindvalue.php
Edit -- https://master.php.net/note/edit/101695
Del: integrated -- https://master.php.net/note/delete/101695/integrated
Del: useless -- https://master.php.net/note/delete/101695/useless
Del: bad code -- https://master.php.net/note/delete/101695/bad+code
Del: spam -- https://master.php.net/note/delete/101695/spam
Del: non-english -- https://master.php.net/note/delete/101695/non-english
Del: in docs -- https://master.php.net/note/delete/101695/in+docs
Del: other reasons-- https://master.php.net/note/delete/101695
Reject -- https://master.php.net/note/reject/101695
Search -- https://master.php.net/manage/user-notes.php