Dragon Blade Posted September 28, 2013 Share Posted September 28, 2013 So I have put this in my class_db_mysql.php - function query_error(){ global $userid,$db; $file = $_SERVER['REQUEST_URI']; if(!isset($_SESSION['error_event_sent'][$file])){ mysql_query("INSERT INTO `mysql_errors` (`me_userid`, `error_msg`, `query_was`, `file`, `error_time`) VALUES('$userid', '".mysql_real_escape_string(mysql_error())."', '{$this->last_query}', '{$file}', unix_timestamp())"); event_add(1, 'MySQL error logged, please check mysql_errors table in the database for more information.'); $_SESSION['error_event_sent'][$file] = true; } } When ever I fail a query it does not report it. My file... <?php if (!defined('MONO_ON')) { exit; } function query_error(){ global $userid,$db; $file = $_SERVER['REQUEST_URI']; if(!isset($_SESSION['error_event_sent'][$file])){ mysql_query("INSERT INTO `mysql_errors` (`me_userid`, `error_msg`, `query_was`, `file`, `error_time`) VALUES('$userid', '".mysql_real_escape_string(mysql_error())."', '{$this->last_query}', '{$file}', unix_timestamp())"); event_add(1, 'MySQL error logged, please check mysql_errors table in the database for more information.'); $_SESSION['error_event_sent'][$file] = true; } } if (!function_exists('error_critical')) { // Umm... die('<h1>Error</h1>' . 'Error handler not present'); } if (!extension_loaded('mysql')) { // dl doesn't work anymore, crash error_critical('Database connection failed', 'MySQL extension not present but required', 'N/A', debug_backtrace(false)); } class database { var $host; var $user; var $pass; var $database; var $persistent = 0; var $last_query; var $result; var $connection_id; var $num_queries = 0; var $start_time; function configure($host, $user, $pass, $database, $persistent = 0) { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->database = $database; $this->persistent = $persistent; return 1; //Success. } function connect() { if (!$this->host) { $this->host = "localhost"; } if (!$this->user) { $this->user = "root"; } if ($this->persistent) { $conn = mysql_pconnect($this->host, $this->user, $this->pass); } else { $conn = mysql_connect($this->host, $this->user, $this->pass, true); } if ($conn === false) { error_critical('Database connection failed', mysql_errno() . ': ' . mysql_error(), 'Attempted to connect to database on ' . $this->host, debug_backtrace(false)); } // @overridecharset mysql $this->connection_id = $conn; if (!mysql_select_db($this->database, $this->connection_id)) { error_critical('Database connection failed', mysql_errno($conn) . ': ' . mysql_error($conn), 'Attempted to select database: ' . $this->database, debug_backtrace(false)); } return $this->connection_id; } function disconnect() { if ($this->connection_id) { mysql_close($this->connection_id); $this->connection_id = 0; return 1; } else { return 0; } } function change_db($database) { if (!mysql_select_db($database, $this->connection_id)) { error_critical('Database change failed', mysql_errno($this->connection_id) . ': ' . mysql_error($this->connection_id), 'Attempted to select database: ' . $database, debug_backtrace(false)); } $this->database = $database; } function query($query) { $this->last_query = $query; $this->num_queries++; $this->result = mysql_query($this->last_query, $this->connection_id); if ($this->result === false) { error_critical('Query failed', mysql_errno($this->connection_id) . ': ' . mysql_error($this->connection_id), 'Attempted to execute query: ' . nl2br($this->last_query), debug_backtrace(false)); } return $this->result; } function fetch_row($result = 0) { if (!$result) { $result = $this->result; } return mysql_fetch_assoc($result); } function num_rows($result = 0) { if (!$result) { $result = $this->result; } return mysql_num_rows($result); } function insert_id() { return mysql_insert_id($this->connection_id); } function fetch_single($result = 0) { if (!$result) { $result = $this->result; } return mysql_result($result, 0, 0); } function easy_insert($table, $data) { $query = "INSERT INTO `$table` ("; $i = 0; foreach ($data as $k => $v) { $i++; if ($i > 1) { $query .= ", "; } $query .= $k; } $query .= ") VALUES("; $i = 0; foreach ($data as $k => $v) { $i++; if ($i > 1) { $query .= ", "; } $query .= "'" . $this->escape($v) . "'"; } $query .= ")"; return $this->query($query); } function query_error(){ global $userid,$db; $file = $_SERVER['REQUEST_URI']; if(!isset($_SESSION['error_event_sent'][$file])){ mysql_query("INSERT INTO `mysql_errors` (`me_userid`, `error_msg`, `query_was`, `file`, `error_time`) VALUES('$userid', '".mysql_real_escape_string(mysql_error())."', '{$this->last_query}', '{$file}', unix_timestamp())"); event_add(1, 'MySQL error logged, please check mysql_errors table in the database for more information.'); $_SESSION['error_event_sent'][$file] = true; } } function escape($text) { return mysql_real_escape_string($text, $this->connection_id); } function affected_rows() { return mysql_affected_rows($this->connection_id); } function free_result($result) { return mysql_free_result($result); } } Quote Link to comment Share on other sites More sharing options...
Jigsaw Posted September 28, 2013 Share Posted September 28, 2013 That would not work I think. There error_handler file would block the class files I think. Quote Link to comment Share on other sites More sharing options...
dnenb Posted September 28, 2013 Share Posted September 28, 2013 I've just edited the basic error handler so that it sends me an email whenever a query fails. Quote Link to comment Share on other sites More sharing options...
Dragon Blade Posted September 28, 2013 Author Share Posted September 28, 2013 Well, I aint cleaver with php :( If I was I would be helping people myself. But can someone help me? Quote Link to comment Share on other sites More sharing options...
dnenb Posted September 28, 2013 Share Posted September 28, 2013 Well, you've created a function and called it query_error(). Are you calling the function anywhere? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.