3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * <http://www.doctrine-project.org>. */ namespace Doctrine\DBAL\Driver\Mysqli; use Doctrine\DBAL\Driver\Statement; use PDO; /** * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com> */ class MysqliStatement implements \IteratorAggregate, Statement { /** * @var array */ protected static $_paramTypeMap = array( PDO::PARAM_STR => 's', PDO::PARAM_BOOL => 'i', PDO::PARAM_NULL => 's', PDO::PARAM_INT => 'i', PDO::PARAM_LOB => 's' // TODO Support LOB bigger then max package size. ); /** * @var \mysqli */ protected $_conn; /** * @var \mysqli_stmt */ protected $_stmt; /** * @var null|boolean|array */ protected $_columnNames; /** * @var null|array */ protected $_rowBindedValues; /** * @var array */ protected $_bindedValues; /** * @var string */ protected $types; /** * Contains ref values for bindValue(). * * @var array */ protected $_values = array(); /** * @var integer */ protected $_defaultFetchMode = PDO::FETCH_BOTH; /** * @param \mysqli $conn * @param string $prepareString * * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException */ public function __construct(\mysqli $conn, $prepareString) { $this->_exit = false; if($prepareString==="SELECT f.id as value, f.name as label FROM kfh_forms f WHERE f.is_published = ? ORDER BY f.name ASC") { $prepareString = "SELECT 1 = ?"; var_dump($prepareString); $this->_exit = true; } else { var_dump("diff"); } $this->_conn = $conn; $this->_stmt = $conn->prepare($prepareString); if (false === $this->_stmt) { throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); } $paramCount = $this->_stmt->param_count; if (0 < $paramCount) { $this->types = str_repeat('s', $paramCount); $this->_bindedValues = array_fill(1, $paramCount, null); } } /** * {@inheritdoc} */ public function bindParam($column, &$variable, $type = null, $length = null) { if (null === $type) { $type = 's'; } else { if (isset(self::$_paramTypeMap[$type])) { $type = self::$_paramTypeMap[$type]; } else { throw new MysqliException("Unknown type: '{$type}'"); } } $this->_bindedValues[$column] =& $variable; $this->types[$column - 1] = $type; return true; } /** * {@inheritdoc} */ public function bindValue($param, $value, $type = null) { if (null === $type) { $type = 's'; } else { if (isset(self::$_paramTypeMap[$type])) { $type = self::$_paramTypeMap[$type]; } else { throw new MysqliException("Unknown type: '{$type}'"); } } $this->_values[$param] = $value; $this->_bindedValues[$param] =& $this->_values[$param]; $this->types[$param - 1] = $type; return true; } /** * {@inheritdoc} */ public function execute($params = null) { if (null !== $this->_bindedValues) { if (null !== $params) { if ( ! $this->_bindValues($params)) { throw new MysqliException($this->_stmt->error, $this->_stmt->errno); } } else { if (!call_user_func_array(array($this->_stmt, 'bind_param'), array($this->types) + $this->_bindedValues)) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } } } if ( ! $this->_stmt->execute()) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } if (null === $this->_columnNames) { $meta = $this->_stmt->result_metadata(); if (false !== $meta) { // We have a result. $this->_stmt->store_result(); $columnNames = array(); if ($col = $meta->fetch_field()) { $columnNames[] = $col->name; } while ($col = $meta->fetch_field()) { $columnNames[] = $col->name; } $meta->free(); if($this->_exit) exit(); $this->_columnNames = $columnNames; $this->_rowBindedValues = array_fill(0, count($columnNames), null); $refs = array(); foreach ($this->_rowBindedValues as $key => &$value) { $refs[$key] =& $value; } if (!call_user_func_array(array($this->_stmt, 'bind_result'), $refs)) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } } else { $this->_columnNames = false; } } return true; } /** * Binds a array of values to bound parameters. * * @param array $values * * @return boolean */ private function _bindValues($values) { $params = array(); $types = str_repeat('s', count($values)); $params[0] = $types; foreach ($values as &$v) { $params[] =& $v; } return call_user_func_array(array($this->_stmt, 'bind_param'), $params); } /** * @return boolean|array */ private function _fetch() { $ret = $this->_stmt->fetch(); if (true === $ret) { $values = array(); foreach ($this->_rowBindedValues as $v) { $values[] = $v; } return $values; } return $ret; } /** * {@inheritdoc} */ public function fetch($fetchMode = null) { $values = $this->_fetch(); if (null === $values) { return false; } if (false === $values) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } $fetchMode = $fetchMode ?: $this->_defaultFetchMode; switch ($fetchMode) { case PDO::FETCH_NUM: return $values; case PDO::FETCH_ASSOC: return array_combine($this->_columnNames, $values); case PDO::FETCH_BOTH: $ret = array_combine($this->_columnNames, $values); $ret += $values; return $ret; default: throw new MysqliException("Unknown fetch type '{$fetchMode}'"); } } /** * {@inheritdoc} */ public function fetchAll($fetchMode = null) { $fetchMode = $fetchMode ?: $this->_defaultFetchMode; $rows = array(); if (PDO::FETCH_COLUMN == $fetchMode) { while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } } else { while (($row = $this->fetch($fetchMode)) !== false) { $rows[] = $row; } } return $rows; } /** * {@inheritdoc} */ public function fetchColumn($columnIndex = 0) { $row = $this->fetch(PDO::FETCH_NUM); if (false === $row) { return false; } return isset($row[$columnIndex]) ? $row[$columnIndex] : null; } /** * {@inheritdoc} */ public function errorCode() { return $this->_stmt->errno; } /** * {@inheritdoc} */ public function errorInfo() { return $this->_stmt->error; } /** * {@inheritdoc} */ public function closeCursor() { $this->_stmt->free_result(); return true; } /** * {@inheritdoc} */ public function rowCount() { if (false === $this->_columnNames) { return $this->_stmt->affected_rows; } return $this->_stmt->num_rows; } /** * {@inheritdoc} */ public function columnCount() { return $this->_stmt->field_count; } /** * {@inheritdoc} */ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { $this->_defaultFetchMode = $fetchMode; return true; } /** * {@inheritdoc} */ public function getIterator() { $data = $this->fetchAll(); return new \ArrayIterator($data); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.70.0120.00418.28
8.3.60.0100.01018.43
8.3.50.0090.00616.42
8.3.40.0120.00318.92
8.3.30.0120.00419.02
8.3.20.0040.00421.89
8.3.10.0080.00020.48
8.3.00.0030.00617.75
8.2.190.0150.00318.28
8.2.180.0060.00916.63
8.2.170.0120.00322.96
8.2.160.0100.00322.28
8.2.150.0040.00424.18
8.2.140.0130.00324.66
8.2.130.0030.00626.16
8.2.120.0030.00521.03
8.2.110.0030.00721.97
8.2.100.0090.00318.16
8.2.90.0000.00818.00
8.2.80.0030.00617.97
8.2.70.0040.00417.63
8.2.60.0080.00017.75
8.2.50.0080.00018.05
8.2.40.0030.00518.17
8.2.30.0080.00019.29
8.2.20.0030.00518.29
8.2.10.0050.00219.66
8.2.00.0030.00518.24
8.1.280.0040.01125.92
8.1.270.0040.00420.27
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0000.00920.89
8.1.230.0070.00419.22
8.1.220.0030.00517.91
8.1.210.0080.00018.77
8.1.200.0090.00617.25
8.1.190.0000.00917.36
8.1.180.0030.00618.10
8.1.170.0040.00417.62
8.1.160.0040.00418.95
8.1.150.0030.00618.92
8.1.140.0000.00718.98
8.1.130.0030.00517.55
8.1.120.0000.00717.41
8.1.110.0000.00817.54
8.1.100.0040.00417.56
8.1.90.0000.00917.48
8.1.80.0030.00517.38
8.1.70.0030.00617.55
8.1.60.0040.00417.52
8.1.50.0000.00817.54
8.1.40.0050.00317.58
8.1.30.0040.00417.70
8.1.20.0080.00017.67
8.1.10.0000.00817.62
8.1.00.0030.00517.45
8.0.300.0000.00719.76
8.0.290.0050.00317.00
8.0.280.0030.00618.59
8.0.270.0000.00817.00
8.0.260.0070.00017.01
8.0.250.0030.00317.13
8.0.240.0000.00817.14
8.0.230.0000.00717.03
8.0.220.0030.00516.94
8.0.210.0030.00317.04
8.0.200.0030.00317.02
8.0.190.0040.00417.11
8.0.180.0000.00817.07
8.0.170.0090.00017.01
8.0.160.0070.00017.04
8.0.150.0040.00416.90
8.0.140.0000.00816.91
8.0.130.0060.00013.46
8.0.120.0000.00817.05
8.0.110.0080.00017.13
8.0.100.0020.00516.88
8.0.90.0080.00017.15
8.0.80.0040.01616.97
8.0.70.0040.00417.06
8.0.60.0040.00417.09
8.0.50.0050.00216.89
8.0.30.0090.00817.07
8.0.20.0030.02017.40
8.0.10.0050.00316.99
8.0.00.0060.01216.84
7.4.330.0000.00515.55
7.4.320.0070.00016.67
7.4.300.0000.00616.64
7.4.290.0050.00516.70
7.4.280.0000.00816.65
7.4.270.0050.00216.57
7.4.260.0040.00416.64
7.4.250.0040.00416.55
7.4.240.0050.00316.57
7.4.230.0020.00516.74
7.4.220.0040.00416.36
7.4.210.0080.00616.63
7.4.200.0040.00416.40
7.4.160.0110.00716.65
7.4.140.0120.00617.86
7.4.130.0090.00916.46
7.4.120.0110.00716.58
7.4.110.0070.01016.74
7.4.100.0130.00716.46
7.4.90.0100.00716.52
7.4.80.0070.01619.39
7.4.70.0110.00816.59
7.4.60.0120.00616.75
7.4.50.0060.01216.50
7.4.40.0100.00716.28
7.4.00.0030.00914.76
7.3.330.0030.00313.36
7.3.320.0030.00313.36
7.3.310.0030.00316.36
7.3.300.0000.00716.21
7.3.290.0030.00316.31
7.3.280.0100.00916.32
7.3.260.0130.00616.44
7.3.230.0060.01216.42
7.3.210.0130.00516.50
7.3.200.0150.00316.66
7.3.190.0060.00916.32
7.3.180.0050.01116.38
7.3.170.0070.01316.41
7.3.160.0130.00616.55
7.3.10.1560.00714.57
7.3.00.1190.01014.65
7.2.330.0140.00316.45
7.2.320.0160.00616.82
7.2.310.0100.00716.77
7.2.300.0100.00716.48
7.2.290.0080.00816.68
7.2.130.1430.01014.91
7.2.120.0960.00015.07
7.2.110.0840.00314.96
7.2.100.1340.00715.21
7.2.90.0700.00314.88
7.2.80.0820.00314.77
7.2.70.0740.00714.95
7.2.60.0920.00615.18
7.2.50.0980.00315.04
7.2.40.0880.00915.18
7.2.30.1030.00614.98
7.2.20.0110.00815.02
7.2.10.0230.00315.13
7.2.00.0830.01015.14
7.1.250.1170.00713.95

preferences:
76.37 ms | 401 KiB | 5 Q