public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) { if (is_array($sql)) { return $this->queryArray($sql, $dieOnError, $msg, $suppress); } parent::countQuery($sql); $this->log->info('Query: ' . $sql); $this->checkConnection(); $db = $this->getDatabase(); $result = false; $stmt = $suppress ? @db2_prepare($db, $sql) : db2_prepare($db, $sql); if ($stmt) { $sp_msg = null; if ($this->bindPreparedSqlParams($sql, $suppress, $stmt, $sp_msg)) { $this->query_time = microtime(true); $rc = $suppress ? @db2_execute($stmt) : db2_execute($stmt); $this->query_time = microtime(true) - $this->query_time; $this->log->info('Query Execution Time: ' . $this->query_time); if (!$rc) { $this->log->error("Query Failed: {$sql}"); $stmt = false; // Making sure we don't use the statement resource for error reporting } else { $result = $stmt; if (isset($sp_msg) && $sp_msg != '') { $this->log->info("Return message from stored procedure call '{$sql}': {$sp_msg}"); } if ($this->dump_slow_queries($sql)) { $this->track_slow_queries($sql); } } } else { $this->log->error("Failed to bind parameter for query : {$sql}"); } } if ($keepResult) { $this->lastResult = $result; } if ($this->checkError($msg . ' Query Failed: ' . $sql, $dieOnError)) { return false; } $matches = array(); if (preg_match('/^\\W*alter\\W+table\\W+(\\w+)/mi', $sql, $matches)) { if ($this->tableExists($matches[1])) { $this->reorgTable($matches[1]); } } return $result; }
/** * Fill in data for prepated statement * @param array $data * @param string $msg Error message * @return boolean */ protected function prepareStatementData(array $data, $param_count, $msg) { if (!$this->stmt) { $this->DBM->registerError($msg, "No prepared statement to execute"); return false; } $this->DBM->countQuery($this->parsedSQL); $GLOBALS['log']->info("Executing Query: {$this->parsedSQL} with " . var_export($data, true)); $this->DBM->query_time = microtime(true); if ($param_count > count($data)) { $this->DBM->registerError($msg, "Incorrect number of elements. Expected {$param_count} but got " . count($data)); return false; } if (!empty($data)) { reset($data); // bind the variables for ($i = 0; $i < $param_count; $i++) { $this->bound_vars[$i] = current($data); next($data); } } return true; }
/** * Parses and runs queries * * @param string $sql SQL Statement to execute * @param bool $dieOnError True if we want to call die if the query returns errors * @param string $msg Message to log if error occurs * @param bool $suppress Flag to suppress all error output unless in debug logging mode. * @param bool $autofree True if we want to push this result into the $lastResult array. * @return resource result set */ public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $autofree = false) { parent::countQuery($sql); $GLOBALS['log']->info('Query:' . $sql); $this->checkConnection(); //$this->freeResult(); $this->query_time = microtime(true); $this->lastsql = $sql; if ($suppress == true) { } else { $result = mysql_query($sql, $this->database); } $this->lastmysqlrow = -1; $this->query_time = microtime(true) - $this->query_time; $GLOBALS['log']->info('Query Execution Time:' . $this->query_time); $this->checkError($msg . ' Query Failed:' . $sql . '::', $dieOnError); if ($autofree) { $this->lastResult[] =& $result; } return $result; }
/** * Parses and runs queries * * @param string $sql SQL Statement to execute * @param bool $dieOnError True if we want to call die if the query returns errors * @param string $msg Message to log if error occurs * @param bool $suppress Flag to suppress all error output unless in debug logging mode. * @param bool $keepResult True if we want to push this result into the $lastResult array. * @return resource result set */ public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) { if (is_array($sql)) { return $this->queryArray($sql, $dieOnError, $msg, $suppress); } parent::countQuery($sql); $GLOBALS['log']->info('Query:' . $sql); $this->checkConnection(); $this->query_time = microtime(true); $this->lastsql = $sql; $result = $suppress ? @mysql_query($sql, $this->database) : mysql_query($sql, $this->database); $this->query_time = microtime(true) - $this->query_time; $GLOBALS['log']->info('Query Execution Time:' . $this->query_time); if ($keepResult) { $this->lastResult = $result; } $this->checkError($msg . ' Query Failed:' . $sql . '::', $dieOnError); return $result; }
/** * Parses and runs queries * * @param string $sql SQL Statement to execute * @param bool $dieOnError True if we want to call die if the query returns errors * @param string $msg Message to log if error occurs * @param bool $suppress Flag to suppress all error output unless in debug logging mode. * @param bool $keepResult True if we want to push this result into the $lastResult var. * @return resource result set */ public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) { if (is_array($sql)) { return $this->queryArray($sql, $dieOnError, $msg, $suppress); } parent::countQuery($sql); $GLOBALS['log']->info('Query: ' . $sql); $this->checkConnection(); $this->query_time = microtime(true); $db = $this->getDatabase(); $result = false; $stmt = $suppress ? @oci_parse($db, $sql) : oci_parse($db, $sql); if (!$this->checkError("{$msg} Parse Failed: {$sql}", $dieOnError)) { $exec_result = $suppress ? @oci_execute($stmt) : oci_execute($stmt); $this->query_time = microtime(true) - $this->query_time; $GLOBALS['log']->info('Query Execution Time: ' . $this->query_time); if ($this->dump_slow_queries($sql)) { $this->track_slow_queries($sql); } if ($exec_result) { $result = $stmt; } } $this->lastQuery = $sql; if ($keepResult) { $this->lastResult = $result; } if ($this->checkError($msg . ' Query Failed: ' . $sql, $dieOnError, $stmt)) { return false; } return $result; }