ILIAS  release_4-4 Revision
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 1434 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 1446 of file mysqli.php.

References MDB2_Driver_Common\$connection, $data, $query, $result, PEAR\isError(), MDB2_ERROR_NOT_FOUND, MDB2_Driver_Common\query(), and ilDB\quote().

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

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

1612  {
1613  if (is_null($this->positions)) {
1614  return $this->db->raiseError(MDB2_ERROR, null, null,
1615  'Prepared statement has already been freed', __FUNCTION__);
1616  }
1617  $result = MDB2_OK;
1618 
1619  if (is_object($this->statement)) {
1620  if (!@mysqli_stmt_close($this->statement)) {
1621  $result = $this->db->raiseError(null, null, null,
1622  'Could not free statement', __FUNCTION__);
1623  }
1624  } elseif (!is_null($this->statement)) {
1625  $connection = $this->db->getConnection();
1626  if (PEAR::isError($connection)) {
1627  return $connection;
1628  }
1629 
1630  $query = 'DEALLOCATE PREPARE '.$this->statement;
1631  $result = $this->db->_doQuery($query, true, $connection);
1632  }
1633 
1634  parent::free();
1635  return $result;
1636  }
$result
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:67
const MDB2_ERROR
Definition: MDB2.php:68
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:

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