@ 2019-02-05T15:20:06Z <?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);
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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).
Version System time (s) User time (s) Memory (MiB) 8.3.7 0.012 0.004 18.28 8.3.6 0.010 0.010 18.43 8.3.5 0.009 0.006 16.42 8.3.4 0.012 0.003 18.92 8.3.3 0.012 0.004 19.02 8.3.2 0.004 0.004 21.89 8.3.1 0.008 0.000 20.48 8.3.0 0.003 0.006 17.75 8.2.19 0.015 0.003 18.28 8.2.18 0.006 0.009 16.63 8.2.17 0.012 0.003 22.96 8.2.16 0.010 0.003 22.28 8.2.15 0.004 0.004 24.18 8.2.14 0.013 0.003 24.66 8.2.13 0.003 0.006 26.16 8.2.12 0.003 0.005 21.03 8.2.11 0.003 0.007 21.97 8.2.10 0.009 0.003 18.16 8.2.9 0.000 0.008 18.00 8.2.8 0.003 0.006 17.97 8.2.7 0.004 0.004 17.63 8.2.6 0.008 0.000 17.75 8.2.5 0.008 0.000 18.05 8.2.4 0.003 0.005 18.17 8.2.3 0.008 0.000 19.29 8.2.2 0.003 0.005 18.29 8.2.1 0.005 0.002 19.66 8.2.0 0.003 0.005 18.24 8.1.28 0.004 0.011 25.92 8.1.27 0.004 0.004 20.27 8.1.26 0.008 0.000 26.35 8.1.25 0.008 0.000 28.09 8.1.24 0.000 0.009 20.89 8.1.23 0.007 0.004 19.22 8.1.22 0.003 0.005 17.91 8.1.21 0.008 0.000 18.77 8.1.20 0.009 0.006 17.25 8.1.19 0.000 0.009 17.36 8.1.18 0.003 0.006 18.10 8.1.17 0.004 0.004 17.62 8.1.16 0.004 0.004 18.95 8.1.15 0.003 0.006 18.92 8.1.14 0.000 0.007 18.98 8.1.13 0.003 0.005 17.55 8.1.12 0.000 0.007 17.41 8.1.11 0.000 0.008 17.54 8.1.10 0.004 0.004 17.56 8.1.9 0.000 0.009 17.48 8.1.8 0.003 0.005 17.38 8.1.7 0.003 0.006 17.55 8.1.6 0.004 0.004 17.52 8.1.5 0.000 0.008 17.54 8.1.4 0.005 0.003 17.58 8.1.3 0.004 0.004 17.70 8.1.2 0.008 0.000 17.67 8.1.1 0.000 0.008 17.62 8.1.0 0.003 0.005 17.45 8.0.30 0.000 0.007 19.76 8.0.29 0.005 0.003 17.00 8.0.28 0.003 0.006 18.59 8.0.27 0.000 0.008 17.00 8.0.26 0.007 0.000 17.01 8.0.25 0.003 0.003 17.13 8.0.24 0.000 0.008 17.14 8.0.23 0.000 0.007 17.03 8.0.22 0.003 0.005 16.94 8.0.21 0.003 0.003 17.04 8.0.20 0.003 0.003 17.02 8.0.19 0.004 0.004 17.11 8.0.18 0.000 0.008 17.07 8.0.17 0.009 0.000 17.01 8.0.16 0.007 0.000 17.04 8.0.15 0.004 0.004 16.90 8.0.14 0.000 0.008 16.91 8.0.13 0.006 0.000 13.46 8.0.12 0.000 0.008 17.05 8.0.11 0.008 0.000 17.13 8.0.10 0.002 0.005 16.88 8.0.9 0.008 0.000 17.15 8.0.8 0.004 0.016 16.97 8.0.7 0.004 0.004 17.06 8.0.6 0.004 0.004 17.09 8.0.5 0.005 0.002 16.89 8.0.3 0.009 0.008 17.07 8.0.2 0.003 0.020 17.40 8.0.1 0.005 0.003 16.99 8.0.0 0.006 0.012 16.84 7.4.33 0.000 0.005 15.55 7.4.32 0.007 0.000 16.67 7.4.30 0.000 0.006 16.64 7.4.29 0.005 0.005 16.70 7.4.28 0.000 0.008 16.65 7.4.27 0.005 0.002 16.57 7.4.26 0.004 0.004 16.64 7.4.25 0.004 0.004 16.55 7.4.24 0.005 0.003 16.57 7.4.23 0.002 0.005 16.74 7.4.22 0.004 0.004 16.36 7.4.21 0.008 0.006 16.63 7.4.20 0.004 0.004 16.40 7.4.16 0.011 0.007 16.65 7.4.14 0.012 0.006 17.86 7.4.13 0.009 0.009 16.46 7.4.12 0.011 0.007 16.58 7.4.11 0.007 0.010 16.74 7.4.10 0.013 0.007 16.46 7.4.9 0.010 0.007 16.52 7.4.8 0.007 0.016 19.39 7.4.7 0.011 0.008 16.59 7.4.6 0.012 0.006 16.75 7.4.5 0.006 0.012 16.50 7.4.4 0.010 0.007 16.28 7.4.0 0.003 0.009 14.76 7.3.33 0.003 0.003 13.36 7.3.32 0.003 0.003 13.36 7.3.31 0.003 0.003 16.36 7.3.30 0.000 0.007 16.21 7.3.29 0.003 0.003 16.31 7.3.28 0.010 0.009 16.32 7.3.26 0.013 0.006 16.44 7.3.23 0.006 0.012 16.42 7.3.21 0.013 0.005 16.50 7.3.20 0.015 0.003 16.66 7.3.19 0.006 0.009 16.32 7.3.18 0.005 0.011 16.38 7.3.17 0.007 0.013 16.41 7.3.16 0.013 0.006 16.55 7.3.1 0.156 0.007 14.57 7.3.0 0.119 0.010 14.65 7.2.33 0.014 0.003 16.45 7.2.32 0.016 0.006 16.82 7.2.31 0.010 0.007 16.77 7.2.30 0.010 0.007 16.48 7.2.29 0.008 0.008 16.68 7.2.13 0.143 0.010 14.91 7.2.12 0.096 0.000 15.07 7.2.11 0.084 0.003 14.96 7.2.10 0.134 0.007 15.21 7.2.9 0.070 0.003 14.88 7.2.8 0.082 0.003 14.77 7.2.7 0.074 0.007 14.95 7.2.6 0.092 0.006 15.18 7.2.5 0.098 0.003 15.04 7.2.4 0.088 0.009 15.18 7.2.3 0.103 0.006 14.98 7.2.2 0.011 0.008 15.02 7.2.1 0.023 0.003 15.13 7.2.0 0.083 0.010 15.14 7.1.25 0.117 0.007 13.95
preferences:dark mode live preview
76.37 ms | 401 KiB | 5 Q