ChainablePDOStatement.php

PHP

No description

Guest

Download Edit

<?php
/* vim: set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2: */
class Database extends PDO {
function __construct($dsn, $username="", $password="", $driver_options=array()) {
parent::__construct($dsn,$username,$password, $driver_options);
// Set the statement class to our custom ChainablePDOStatement class
$this->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;
}
}