setAttribute(PDO::ATTR_STATEMENT_CLASS, array('ChainablePDOStatement', array($this))); } } /* * Extend PDOStatement to make functions like bindValue, bindParam and so on * chainable. */ class ChainablePDOStatement extends PDOStatement { protected $pdo; protected function __construct($pdo) { $this->pdo = $pdo; } public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR) { parent::bindValue($parameter, $value, $data_type); return $this; } public function bindParam($paramno, &$param, $type = NULL, $maxlen = NULL, $driverdata = NULL) { parent::bindParam($paramno, $param, $type, $maxlen, $driverdata); return $this; } public function execute($bound_input_params = NULL) { parent::execute($bound_input_params); return $this; } }