ConFoo Montreal 2026: Call for Papers

Voting

: eight plus zero?
(Example: nine)

The Note You're Voting On

goofiq dot no dot spam at antispam dot wp dot pl
15 years ago
bindValue with data_type depend parameter name

<?php

$db
= new PDO (...);
$db -> setAttribute (PDO::ATTR_STATEMENT_CLASS, array ('MY_PDOStatement ', array ($db)));

class
MY_PDOStatement extends PDOStatement {

public function
execute ($input = array ()) {
foreach (
$input as $param => $value) {
if (
preg_match ('/_id$/', $param))
$this -> bindValue ($param, $value, PDO::PARAM_INT);
else
$this -> bindValue ($param, $value, PDO::PARAM_STR);
}
return
parent::execute ();
}

}

?>

<< Back to user notes page

To Top