ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
MDB2_Statement_mysql Class Reference
+ Inheritance diagram for MDB2_Statement_mysql:
+ Collaboration diagram for MDB2_Statement_mysql:

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 1363 of file mysql.php.

Member Function Documentation

◆ _execute()

& MDB2_Statement_mysql::_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 @access private

Reimplemented from MDB2_Statement_Common.

Definition at line 1375 of file mysql.php.

1376 {
1377 if (is_null($this->statement)) {
1378 $result =& parent::_execute($result_class, $result_wrap_class);
1379 return $result;
1380 }
1381 $this->db->last_query = $this->query;
1382 $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));
1383 if ($this->db->getOption('disable_query')) {
1384 $result = $this->is_manip ? 0 : null;
1385 return $result;
1386 }
1387
1388 $connection = $this->db->getConnection();
1389 if (PEAR::isError($connection)) {
1390 return $connection;
1391 }
1392
1393 $query = 'EXECUTE '.$this->statement;
1394 if (!empty($this->positions)) {
1395 $parameters = array();
1396 foreach ($this->positions as $parameter) {
1397 if (!array_key_exists($parameter, $this->values)) {
1398 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
1399 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
1400 }
1401 $value = $this->values[$parameter];
1402 $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
1403 if (is_resource($value) || $type == 'clob' || $type == 'blob') {
1404 if (!is_resource($value) && preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
1405 if ($match[1] == 'file://') {
1406 $value = $match[2];
1407 }
1408 $value = @fopen($value, 'r');
1409 $close = true;
1410 }
1411 if (is_resource($value)) {
1412 $data = '';
1413 while (!@feof($value)) {
1414 $data.= @fread($value, $this->db->options['lob_buffer_length']);
1415 }
1416 if ($close) {
1417 @fclose($value);
1418 }
1419 $value = $data;
1420 }
1421 }
1422 $quoted = $this->db->quote($value, $type);
1423 if (PEAR::isError($quoted)) {
1424 return $quoted;
1425 }
1426 $param_query = 'SET @'.$parameter.' = '.$quoted;
1427 $result = $this->db->_doQuery($param_query, true, $connection);
1428 if (PEAR::isError($result)) {
1429 return $result;
1430 }
1431 }
1432 $query.= ' USING @'.implode(', @', array_values($this->positions));
1433 }
1434
1435 $result = $this->db->_doQuery($query, $this->is_manip, $connection);
1436 if (PEAR::isError($result)) {
1437 return $result;
1438 }
1439
1440 if ($this->is_manip) {
1441 $affected_rows = $this->db->_affectedRows($connection, $result);
1442 return $affected_rows;
1443 }
1444
1445 $result =& $this->db->_wrapResult($result, $this->result_types,
1446 $result_class, $result_wrap_class, $this->limit, $this->offset);
1447 $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result));
1448 return $result;
1449 }
$result
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:71
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
$data

References $data, MDB2_Statement_Common\$query, $result, PEAR\isError(), and MDB2_ERROR_NOT_FOUND.

+ Here is the call graph for this function:

◆ free()

MDB2_Statement_mysql::free ( )

Release resources allocated for the specified prepared query.

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

Reimplemented from MDB2_Statement_Common.

Definition at line 1460 of file mysql.php.

1461 {
1462 if (is_null($this->positions)) {
1463 return $this->db->raiseError(MDB2_ERROR, null, null,
1464 'Prepared statement has already been freed', __FUNCTION__);
1465 }
1466 $result = MDB2_OK;
1467
1468 if (!is_null($this->statement)) {
1469 $connection = $this->db->getConnection();
1470 if (PEAR::isError($connection)) {
1471 return $connection;
1472 }
1473 $query = 'DEALLOCATE PREPARE '.$this->statement;
1474 $result = $this->db->_doQuery($query, true, $connection);
1475 }
1476
1477 parent::free();
1478 return $result;
1479 }
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

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

+ Here is the call graph for this function:

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