You are here

function DB_common::executeEmulateQuery in Flickr API 5

Emulates executing prepared statements if the DBMS not support them

@access protected

Parameters

resource $stmt a DB statement resource returned from execute():

mixed $data array, string or numeric data to be used in: execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

Return value

mixed a string containing the real query run when emulating prepare/execute. A DB_Error object on failure.

See also

DB_common::execute()

1 call to DB_common::executeEmulateQuery()
DB_common::execute in phpFlickr/PEAR/DB/common.php
Executes a DB statement prepared with prepare()

File

phpFlickr/PEAR/DB/common.php, line 986

Class

DB_common
DB_common is the base class from which each database driver class extends

Code

function executeEmulateQuery($stmt, $data = []) {
  $stmt = (int) $stmt;
  $data = (array) $data;
  $this->last_parameters = $data;
  if (count($this->prepare_types[$stmt]) != count($data)) {
    $this->last_query = $this->prepared_queries[$stmt];
    return $this
      ->raiseError(DB_ERROR_MISMATCH);
  }
  $realquery = $this->prepare_tokens[$stmt][0];
  $i = 0;
  foreach ($data as $value) {
    if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) {
      $realquery .= $this
        ->quoteSmart($value);
    }
    elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) {
      $fp = @fopen($value, 'rb');
      if (!$fp) {
        return $this
          ->raiseError(DB_ERROR_ACCESS_VIOLATION);
      }
      $realquery .= $this
        ->quoteSmart(fread($fp, filesize($value)));
      fclose($fp);
    }
    else {
      $realquery .= $value;
    }
    $realquery .= $this->prepare_tokens[$stmt][++$i];
  }
  return $realquery;
}