ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
MDB2_Statement_mysqli Class Reference
+ Inheritance diagram for MDB2_Statement_mysqli:
+ Collaboration diagram for MDB2_Statement_mysqli:

Public Member Functions

_execute ($result_class=true, $result_wrap_class=false)
 Execute a prepared query statement helper method. More...
 
 free ()
 Release resources allocated for the specified prepared query. More...
 
- Public Member Functions inherited from MDB2_Statement_Common
 __construct (&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
 Constructor. More...
 
 MDB2_Statement_Common (&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
 PHP 4 Constructor. More...
 
 bindValue ($parameter, $value, $type=null)
 Set the value of a parameter of a prepared query. More...
 
 bindValueArray ($values, $types=null)
 Set the values of multiple a parameter of a prepared query in bulk. More...
 
 bindParam ($parameter, &$value, $type=null)
 Bind a variable to a parameter of a prepared query. More...
 
 bindParamArray (&$values, $types=null)
 Bind the variables of multiple a parameter of a prepared query in bulk. More...
 
execute ($values=null, $result_class=true, $result_wrap_class=false)
 Execute a prepared query statement. More...
 
_execute ($result_class=true, $result_wrap_class=false)
 Execute a prepared query statement helper method. More...
 
 free ()
 Release resources allocated for the specified prepared query. More...
 

Additional Inherited Members

- Data Fields inherited from MDB2_Statement_Common
 $db
 
 $statement
 
 $query
 
 $result_types
 
 $types
 
 $values = array()
 
 $limit
 
 $offset
 
 $is_manip
 

Detailed Description

Definition at line 1451 of file mysqli.php.

Member Function Documentation

◆ _execute()

& MDB2_Statement_mysqli::_execute (   $result_class = true,
  $result_wrap_class = false 
)

Execute a prepared query statement helper method.

Parameters
mixed$result_classstring which specifies which result class to use
mixed$result_wrap_classstring which specifies which class to wrap results in
Returns
mixed a result handle or MDB2_OK on success, a MDB2 error on failure private

Definition at line 1463 of file mysqli.php.

References MDB2_Driver_Common\$connection, $data, $i, $query, $result, $type, array, PEAR\isError(), MDB2_ERROR_NOT_FOUND, and MDB2_Driver_Common\query().

1464  {
1465  if (is_null($this->statement)) {
1466  $result =& parent::_execute($result_class, $result_wrap_class);
1467  return $result;
1468  }
1469  $this->db->last_query = $this->query;
1470  $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));
1471  if ($this->db->getOption('disable_query')) {
1472  $result = $this->is_manip ? 0 : null;
1473  return $result;
1474  }
1475 
1476  $connection = $this->db->getConnection();
1477  if (PEAR::isError($connection)) {
1478  return $connection;
1479  }
1480 
1481  if (!is_object($this->statement)) {
1482  $query = 'EXECUTE '.$this->statement;
1483  }
1484  if (!empty($this->positions)) {
1485  $parameters = array(0 => $this->statement, 1 => '');
1486  $lobs = array();
1487  $i = 0;
1488  foreach ($this->positions as $parameter) {
1489  if (!array_key_exists($parameter, $this->values)) {
1490  return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
1491  'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
1492  }
1493  $value = $this->values[$parameter];
1494  $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
1495  if (!is_object($this->statement)) {
1496  if (is_resource($value) || $type == 'clob' || $type == 'blob') {
1497  if (!is_resource($value) && preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
1498  if ($match[1] == 'file://') {
1499  $value = $match[2];
1500  }
1501  $value = @fopen($value, 'r');
1502  $close = true;
1503  }
1504  if (is_resource($value)) {
1505  $data = '';
1506  while (!@feof($value)) {
1507  $data.= @fread($value, $this->db->options['lob_buffer_length']);
1508  }
1509  if ($close) {
1510  @fclose($value);
1511  }
1512  $value = $data;
1513  }
1514  }
1515  $quoted = $this->db->quote($value, $type);
1516  if (PEAR::isError($quoted)) {
1517  return $quoted;
1518  }
1519  $param_query = 'SET @'.$parameter.' = '.$quoted;
1520  $result = $this->db->_doQuery($param_query, true, $connection);
1521  if (PEAR::isError($result)) {
1522  return $result;
1523  }
1524  } else {
1525  if (is_resource($value) || $type == 'clob' || $type == 'blob') {
1526  $parameters[] = null;
1527  $parameters[1].= 'b';
1528  $lobs[$i] = $parameter;
1529  } else {
1530  $parameters[] = $this->db->quote($value, $type, false);
1531  $parameters[1].= $this->db->datatype->mapPrepareDatatype($type);
1532  }
1533  ++$i;
1534  }
1535  }
1536 
1537  if (!is_object($this->statement)) {
1538  $query.= ' USING @'.implode(', @', array_values($this->positions));
1539  } else {
1540 
1541  // pear bug #17024: php 5.3 changed mysqli_stmt_bind_param()
1542  $stmt_params = array();
1543  foreach ($parameters as $k => &$value) {
1544  $stmt_params[$k] = &$value;
1545  }
1546 
1547  $result = @call_user_func_array('mysqli_stmt_bind_param', $stmt_params);
1548  if ($result === false) {
1549  $err =& $this->db->raiseError(null, null, null,
1550  'Unable to bind parameters', __FUNCTION__);
1551  return $err;
1552  }
1553 
1554  foreach ($lobs as $i => $parameter) {
1555  $value = $this->values[$parameter];
1556  $close = false;
1557  if (!is_resource($value)) {
1558  $close = true;
1559  if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
1560  if ($match[1] == 'file://') {
1561  $value = $match[2];
1562  }
1563  $value = @fopen($value, 'r');
1564  } else {
1565  $fp = @tmpfile();
1566  @fwrite($fp, $value);
1567  @rewind($fp);
1568  $value = $fp;
1569  }
1570  }
1571  while (!@feof($value)) {
1572  $data = @fread($value, $this->db->options['lob_buffer_length']);
1573  @mysqli_stmt_send_long_data($this->statement, $i, $data);
1574  }
1575  if ($close) {
1576  @fclose($value);
1577  }
1578  }
1579  }
1580  }
1581 
1582  if (!is_object($this->statement)) {
1583  $result = $this->db->_doQuery($query, $this->is_manip, $connection);
1584  if (PEAR::isError($result)) {
1585  return $result;
1586  }
1587 
1588  if ($this->is_manip) {
1589  $affected_rows = $this->db->_affectedRows($connection, $result);
1590  return $affected_rows;
1591  }
1592 
1593  $result =& $this->db->_wrapResult($result, $this->result_types,
1594  $result_class, $result_wrap_class, $this->limit, $this->offset);
1595  } else {
1596  if (!@mysqli_stmt_execute($this->statement)) {
1597  $err =& $this->db->raiseError(null, null, null,
1598  'Unable to execute statement', __FUNCTION__);
1599  return $err;
1600  }
1601 
1602  if ($this->is_manip) {
1603  $affected_rows = @mysqli_stmt_affected_rows($this->statement);
1604  return $affected_rows;
1605  }
1606 
1607  if ($this->db->options['result_buffering']) {
1608  @mysqli_stmt_store_result($this->statement);
1609  }
1610 
1611  $result =& $this->db->_wrapResult($this->statement, $this->result_types,
1612  $result_class, $result_wrap_class, $this->limit, $this->offset);
1613  }
1614 
1615  $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result));
1616  return $result;
1617  }
$result
$type
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:76
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ free()

MDB2_Statement_mysqli::free ( )

Release resources allocated for the specified prepared query.

Returns
mixed MDB2_OK on success, a MDB2 error on failure public

Definition at line 1628 of file mysqli.php.

References MDB2_Driver_Common\$connection, $query, $result, PEAR\isError(), MDB2_ERROR, and MDB2_OK.

1629  {
1630  if (is_null($this->positions)) {
1631  return $this->db->raiseError(MDB2_ERROR, null, null,
1632  'Prepared statement has already been freed', __FUNCTION__);
1633  }
1634  $result = MDB2_OK;
1635 
1636  if (is_object($this->statement)) {
1637  if (!@mysqli_stmt_close($this->statement)) {
1638  $result = $this->db->raiseError(null, null, null,
1639  'Could not free statement', __FUNCTION__);
1640  }
1641  } elseif (!is_null($this->statement)) {
1642  $connection = $this->db->getConnection();
1643  if (PEAR::isError($connection)) {
1644  return $connection;
1645  }
1646 
1647  $query = 'DEALLOCATE PREPARE '.$this->statement;
1648  $result = $this->db->_doQuery($query, true, $connection);
1649  }
1650 
1651  parent::free();
1652  return $result;
1653  }
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
$result
const MDB2_ERROR
Definition: MDB2.php:73
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: