From:
Operating system: Any
PHP version: 5.3.3
Package: MySQLi related
Bug Type: Bug
Bug description:Mysqli Object use is much slower than Mysqli procedural use
Description:
------------
mysqli_query()
is MUCH MUCH FASTER than
mysqli::query()
also MySQL PDO sucks as PDO is for dumb developers.
Test script:
---------------
==== OBJECT STYLE:
<?php
echo 'object:<br>';
for($y=0;$y<10;++$y){
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];$starttime = $mtime;
include 'isett.iphp';
$mysqli=new mysqli($isql['h'],$isql['u'],$isql['p'],$isql['d']);
if(mysqli_connect_errno()) die('Connection Error '.mysqli_connect_errno().'
: '.mysqli_connect_error());
$mysqli->set_charset('utf8');
$mysqli->query("CREATE TABLE IF NOT EXISTS persad_dsa (`id` SMALLINT(3)
UNSIGNED NOT NULL AUTO_INCREMENT,`a_name` VARCHAR(100) CHARACTER SET utf8
COLLATE utf8_general_ci NOT NULL,`a_desc` VARCHAR(200) CHARACTER SET utf8
COLLATE utf8_general_ci NOT NULL,PRIMARY KEY(`id`))ENGINE=MYISAM");
for($i=1;$i<2000;++$i){
$mysqli->query('INSERT INTO persad_dsa (a_name,a_desc)
VALUES(\'=+=+=+=+=+'.($i+1000).'+=+=+=+=+=\',\'------------------------------------------------'.($i+321).'-------\')');
}
$query="SELECT * FROM persad_dsa";
if($result=$mysqli->query($query)){
while($row=$result->fetch_assoc()){
$array[]='|-'.$row['id'].'|'.$row['a_name'].'|'.$row['a_desc'].'-|';
}
$result->close();
}
$mysqli->query("DROP TABLE IF EXISTS persad_dsa");
$mysqli->close();
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];echo $mtime-$starttime.'<br>';
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
}
echo '---<br>procedural:<br>';
for($y=0;$y<10;++$y){
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];$starttime = $mtime;
include 'isett.iphp';
$mysqli=mysqli_connect($isql['h'],$isql['u'],$isql['p'],$isql['d']);
if(mysqli_connect_errno()) die('Connection Error '.mysqli_connect_errno().'
: '.mysqli_connect_error());
mysqli_set_charset($mysqli,'utf8');
mysqli_query($mysqli,"CREATE TABLE IF NOT EXISTS persad_dsa (`id`
SMALLINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,`a_name` VARCHAR(100)
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,`a_desc` VARCHAR(200)
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,PRIMARY
KEY(`id`))ENGINE=MYISAM");
for($i=1;$i<2000;++$i){
mysqli_query($mysqli,'INSERT INTO persad_dsa (a_name,a_desc)
VALUES(\'=+=+=+=+=+'.($i+1000).'+=+=+=+=+=\',\'------------------------------------------------'.($i+321).'-------\')');
}
$query="SELECT * FROM persad_dsa";
if($result=mysqli_query($mysqli,$query)){
while($row=mysqli_fetch_assoc($result)){
$array[]='|-'.$row['id'].'|'.$row['a_name'].'|'.$row['a_desc'].'-|';
}
mysqli_free_result($result);
}
mysqli_query($mysqli,"DROP TABLE IF EXISTS persad_dsa");
mysqli_close($mysqli);
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];echo $mtime-$starttime.'<br>';
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
}
?>
//==== PROCEDURAL STYLE
<?php
echo 'procedural:<br>';
for($y=0;$y<10;++$y){
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];$starttime = $mtime;
include 'isett.iphp';
$mysqli=mysqli_connect($isql['h'],$isql['u'],$isql['p'],$isql['d']);
if(mysqli_connect_errno()) die('Connection Error '.mysqli_connect_errno().'
: '.mysqli_connect_error());
mysqli_set_charset($mysqli,'utf8');
mysqli_query($mysqli,"CREATE TABLE IF NOT EXISTS persad_dsa (`id`
SMALLINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,`a_name` VARCHAR(100)
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,`a_desc` VARCHAR(200)
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,PRIMARY
KEY(`id`))ENGINE=MYISAM");
for($i=1;$i<2000;++$i){
mysqli_query($mysqli,'INSERT INTO persad_dsa (a_name,a_desc)
VALUES(\'=+=+=+=+=+'.($i+1000).'+=+=+=+=+=\',\'------------------------------------------------'.($i+321).'-------\')');
}
$query="SELECT * FROM persad_dsa";
if($result=mysqli_query($mysqli,$query)){
while($row=mysqli_fetch_assoc($result)){
$array[]='|-'.$row['id'].'|'.$row['a_name'].'|'.$row['a_desc'].'-|';
}
mysqli_free_result($result);
}
mysqli_query($mysqli,"DROP TABLE IF EXISTS persad_dsa");
mysqli_close($mysqli);
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];echo $mtime-$starttime.'<br>';
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
}
echo '---<br>object:<br>';
for($y=0;$y<10;++$y){
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];$starttime = $mtime;
include 'isett.iphp';
$mysqli=new mysqli($isql['h'],$isql['u'],$isql['p'],$isql['d']);
if(mysqli_connect_errno()) die('Connection Error '.mysqli_connect_errno().'
: '.mysqli_connect_error());
$mysqli->set_charset('utf8');
$mysqli->query("CREATE TABLE IF NOT EXISTS persad_dsa (`id` SMALLINT(3)
UNSIGNED NOT NULL AUTO_INCREMENT,`a_name` VARCHAR(100) CHARACTER SET utf8
COLLATE utf8_general_ci NOT NULL,`a_desc` VARCHAR(200) CHARACTER SET utf8
COLLATE utf8_general_ci NOT NULL,PRIMARY KEY(`id`))ENGINE=MYISAM");
for($i=1;$i<2000;++$i){
$mysqli->query('INSERT INTO persad_dsa (a_name,a_desc)
VALUES(\'=+=+=+=+=+'.($i+1000).'+=+=+=+=+=\',\'------------------------------------------------'.($i+321).'-------\')');
}
$query="SELECT * FROM persad_dsa";
if($result=$mysqli->query($query)){
while($row=$result->fetch_assoc()){
$array[]='|-'.$row['id'].'|'.$row['a_name'].'|'.$row['a_desc'].'-|';
}
$result->close();
}
$mysqli->query("DROP TABLE IF EXISTS persad_dsa");
$mysqli->close();
$mtime = explode(' ',microtime());$mtime = (float)$mtime[1] +
(float)$mtime[0];echo $mtime-$starttime.'<br>';
$mtime='';$starttime='';$isql=array();$mysqli='';$i=1;$query='';$array=array();$result='';$row=array();
}
?>
//====
Expected result:
----------------
PHP 5.3 is going in a wrong direction dudes !
Actual result:
--------------
I can't predict
--
Edit bug report at http://bugs.php.net/bug.php?id=53482&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53482&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53482&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53482&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53482&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53482&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53482&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53482&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53482&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53482&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53482&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53482&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53482&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53482&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53482&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53482&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53482&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53482&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53482&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53482&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53482&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53482&r=mysqlcfg