note 73318 added to ref.pdo

From: Date: Sat, 17 Feb 2007 19:52:59 +0000
Subject: note 73318 added to ref.pdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-123518@lists.php.net to get a copy of this message
Simple example to extends PDO <?php class connexion extends PDO { public $query = null; public function prepare( $statement, $driver_options = array() ) { $this->query = $statement; return parent::prepare( $statement, $driver_options = array() ); } public function last_query() { return $this->query; } } class connexion_statement extends PDOStatement { protected $pdo; protected function __construct($pdo) { $this->pdo = $pdo; } // return first column of first row public function fetchFirst() { $row = $this->fetch( PDO::FETCH_NUM ); return $row[0]; } // real cast number public function fetch( $fetch_style = null, $cursor_orientation = null, $cursor_offset = null ) { $row = parent::fetch( $fetch_style, $cursor_orientation, $cursor_offset ); if( is_array($row) ) foreach( $row as $key => $value ) if( strval(intval($value)) === $value ) $row[$key] = intval($value); elseif( strval(floatval($value)) === $value ) $row[$key] = floatval($value); return $row; } // permit $prepare->execute( $arg1, $arg2, ... ); public function execute( $args = null ) { if( is_array( $args ) ) return parent::execute( $args ); else { $args = func_get_args(); return eval( 'return parent::execute( $args );' ); } } public function last_query() { return $this->pdo->last_query(); } } $pdo = new connexion( ... ); $pdo->setAttribute( PDO::ATTR_STATEMENT_CLASS, array( 'connexion_statement', array($pdo) ) ); ?> ---- Server IP: 194.246.101.61 Probable Submitter: 212.129.63.1 ---- Manual Page -- http://www.php.net/manual/en/ref.pdo.php Edit -- https://master.php.net/note/edit/73318 Del: integrated -- https://master.php.net/note/delete/73318/integrated Del: useless -- https://master.php.net/note/delete/73318/useless Del: bad code -- https://master.php.net/note/delete/73318/bad+code Del: spam -- https://master.php.net/note/delete/73318/spam Del: non-english -- https://master.php.net/note/delete/73318/non-english Del: in docs -- https://master.php.net/note/delete/73318/in+docs Del: other reasons-- https://master.php.net/note/delete/73318 Reject -- https://master.php.net/note/reject/73318 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123518) next »