function test_query_execution_time($sql, $debug = false, $output = false) { $start = microtime(true); $q = exec_sql($sql); $time = microtime(true) - $start; if ($debug) { $debug = "{$sql}<br/>{$time}<br/><br/>"; if ($output) { print $debug; } else { log_query($debug); } } return $q; }
public function query($sql) { $this->sql = $sql; if ($this->result = mysql_query($sql, $this->connection)) { } else { print $sql . "\n<br/>\n"; elog('Query failed: ' . mysql_error() . ' SQL: ' . $this->sql, 'error'); die('Query failed: ' . mysql_error()); } if ($this->log) { log_query($this->sql, $this->vars); } return $this; }
public function query($sql) { $this->sql = $sql; if ($this->result = mysql_query($sql, $this->connection)) { } else { elog('Query failed: ' . mysql_error() . ' SQL: ' . $this->sql, 'error'); $res = array('status' => 500, 'msg' => '', 'sql' => $sql); $res['msg'] = 'Query failed: ' . mysql_error(); die(json_encode($res)); } if ($this->log) { log_query($this->sql, $this->vars); } return $this; }
function execute_query($query) { global $global; //IDENTIFIANT MYSQL $MYSQL_HOST = $global['MYSQL_HOST']; $MYSQL_USER = $global['MYSQL_USER']; $MYSQL_PASS = $global['MYSQL_PASS']; $tbsp = $global['TBSP']; $connected = mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS) or die("Erreur de connexion au serveur."); $db = mysql_select_db($tbsp) or die("erreur de connexion base: {$tbsp}!!"); //echo '***'.$query.'***'; log_query($query); $stmt = mysql_query($query, $connected); if (gettype($stmt) == "resource") { $results = array(); $nbrows = mysql_num_rows($stmt); while ($row = mysql_fetch_assoc($stmt)) { foreach ($row as $key => $val) { $results[strtoupper($key)][] = $val; } //finFOREACH } //finWHILE //print_r($results); //echo '<br><br>'; mysql_free_result($stmt); //libère la ressource mysql_close($connected); //fin conn } else { echo '<br> #### Impossible d\'executer la requete : ' . mysql_error() . ' #### <br>'; $results = null; $nbrows = null; } return $results; }
function execute_with_array($sql, $args) { foreach ($args as &$arg) { if (is_array($arg)) { if (count($arg) == 0) { $arg = array(-1); } $parts = array(); foreach ($arg as $part) { $parts[] = "'" . mysql_real_escape_string("{$part}") . "'"; } $arg = "(" . implode(",", $parts) . ")"; } else { $arg = "'" . mysql_real_escape_string("{$arg}") . "'"; } } $sql = str_replace("?", "%s", $sql); array_unshift($args, $sql); $sql = call_user_func_array('sprintf', $args); log_query($sql); $res = mysql_query($sql); if (!$res) { die("<h1>Ошибка работы с базой данных</h1>" . "<p>При исполнении запроса возникла следующая ошибка: " . htmlentities(mysql_error()) . "</p>" . "<p>Неудавшийся запрос: <code>" . htmlentities($sql) . "</code></p>"); } return mysql_affected_rows(); }
static function send_logged_queries () { set_error_handler(array('self' , 'error_handler')); try { self::$query_line = null; if (! is_file(self::log_name('query'))) { restore_error_handler(); return; } // Fixed: If the processing takes more than one second the self::log_name returns a different filename due to time() being used $query_log = self::log_name('query'); $send_log = self::log_name('send'); rename($query_log, $send_log); $fh = fopen($send_log, "r"); $file = ""; if ($fh) { while (! feof($fh)) { $file = fgets($fh); } $queryArr = explode("/", $file); //just split the lines by the on delimiter-like char we have foreach ($queryArr as $query) { $qstring = "/" . $query; // add it back print "SENDING $qstring\n"; try { self::send_query($qstring); } catch (Exception $e) { if (self::$query_line) log_query(self::$query_line); log_error($e->getMessage()); } } } /*$fh = fopen($send_log, "r"); if ($fh) { while (! feof($fh)) { self::$query_line = fgets($fh); <-----THIS READS THE ENTIRE FILE INTO, NOT A LINE try { self::send_query(self::$query_line); } catch (Exception $e) { if (self::$query_line) log_query(self::$query_line); log_error($e->getMessage()); } } fclose($fh); }*/ fclose($fh); unlink($send_log); self::$query_line = null; restore_error_handler(); } catch (Exception $e) { restore_error_handler(); self::log_error($e->getMessage()); } }