* @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software Foundation, Inc. http://www.fsf.org/ * This file is part of phpGroupWare. * * phpGroupWare is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * phpGroupWare is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with phpGroupWare; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @license http://www.gnu.org/licenses/gpl.html GNU General Public License * @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/ * @package property * @version $Id$ */ /** * Test script for PDO vs ADOdb * */ $GLOBALS['phpgw_info']['flags'] = array ( 'currentapp' => 'property' ); include_once('../header.inc.php'); // $type = 'ADOdb'; $type = 'PDO'; // $check_prepared = true; $check_prepared = false; if($type == 'ADOdb') { $db = createObject('phpgwapi.db'); } else { $db = createObject('property.db_pdo'); $db->fetchmode == 'ASSOC'; } $db->transaction_begin(); $sql = "CREATE TABLE pdo_test( id integer NOT NULL, descr character varying(100), CONSTRAINT pdo_test_pkey PRIMARY KEY (id))"; $db->query($sql,__LINE__,__FILE__,true); $j = 100000; $timer_start = perfgetmicrotime(); for ($i=1; $i < $j+1; $i++) { $db->query('INSERT INTO pdo_test (id, descr)' . " VALUES ({$i}, 'Description for a tiny test at line {$i}')",__LINE__,__FILE__,true); } $timer_stop = perfgetmicrotime(); echo "
Type: {$type}, INSERT count= {$j}, Time spent: " . ($timer_stop - $timer_start) . '
'; if($type == 'PDO' && $check_prepared) { $sql = "DELETE FROM pdo_test"; $db->query($sql,__LINE__,__FILE__,true); /* INSERT PREPARED */ $sql = 'INSERT INTO pdo_test (id, descr) VALUES (?,?)'; $timer_start = perfgetmicrotime(); for ($i=1; $i < $j+1; $i++) { $valueset[] = array ( 1 => array ( 'value' => $i, 'type' => 'int' ), 2 => array ( 'value' => "Description for a tiny test on prepared statement at line {$i}", 'type' => 'string' ) ); } $db->insert($sql, $valueset, __LINE__,__FILE__); $timer_stop = perfgetmicrotime(); echo "
Type: {$type}, INSERT count= {$j}, prepared statements, Time spent: " . ($timer_stop - $timer_start) . '
'; /* SELECT PREPARED */ $sql = 'SELECT * FROM pdo_test WHERE id = ?'; $timer_start = perfgetmicrotime(); $ret = array(); for ($i=1; $i < $j+1; $i++) { $params = array($i); $db->select($sql, $params, __LINE__,__FILE__); $db->next_record(); $ret[] = array ( 'id' => $db->f('id'), 'descr' => $db->f('descr') ); } $timer_stop = perfgetmicrotime(); echo "
Type: {$type}, SELECT count= {$j}, prepared statements for each ID, Time spent: " . ($timer_stop - $timer_start) . '
'; // _debug_array($ret); /* SELECT PLAIN */ $timer_start = perfgetmicrotime(); $ret = array(); for ($i=1; $i < $j+1; $i++) { $sql = "SELECT * FROM pdo_test WHERE id = {$i}"; $db->query($sql, __LINE__,__FILE__); $db->next_record(); $ret[] = array ( 'id' => $db->f('id'), 'descr' => $db->f('descr') ); } $timer_stop = perfgetmicrotime(); echo "
Type: {$type}, SELECT count= {$j}, plain for each ID, Time spent: " . ($timer_stop - $timer_start) . '
'; // _debug_array($ret); } $timer_start = perfgetmicrotime(); $ret = array(); $sql = "SELECT * FROM pdo_test ORDER BY id ASC"; $db->query($sql,__LINE__,__FILE__); while($db->next_record()) { $ret[] = array ( 'id' => $db->f('id'), 'descr' => $db->f('descr') ); } // _debug_array($ret); $timer_stop = perfgetmicrotime(); echo "
Type: {$type}, SELECT count= {$j}, Time spent: " . ($timer_stop - $timer_start) . '
'; $sql = "DROP TABLE pdo_test"; $db->query($sql,__LINE__,__FILE__,true); $db->transaction_commit(); exit;