note 101695 deleted from pdostatement.bindvalue by danbrown

From: Date: Wed, 05 Jan 2011 21:13:27 +0000
Subject: note 101695 deleted from pdostatement.bindvalue by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175471@lists.php.net to get a copy of this message
Note Submitter: schindhelm at gmail dot com ---- 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); ?>

« previous php.notes (#175471) next »