Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // (C) 2012, All rights reversed
- class ezSQLcore
- {
- public $prefix = '';
- public $trace = false;
- public $debug_all = false;
- public $debug_called = false;
- public $vardump_called = false;
- public $show_errors = true;
- public $num_queries = 0;
- public $last_query = null;
- public $last_error = null;
- public $col_info = null;
- public $captured_errors = array();
- public $cache_dir = false;
- public $cache_queries = false;
- public $cache_inserts = false;
- public $use_disk_cache = false;
- public $cache_timeout = 24;
- public $timers = array();
- public $total_query_time = 0;
- public $db_connect_time = 0;
- public $trace_log = array();
- public $use_trace_log = false;
- public $sql_log_file = false;
- public $do_profile = false;
- public $profile_times = array();
- public $field_types = array();
- public $real_escape = false;
- public $debug_echo_is_on = true;
- public function ezSQLcore()
- {
- }
- public function register_error($err_str)
- {
- $this->last_error = $err_str;
- $this->captured_errors[] = array('error_str' => $err_str, 'query' => $this->last_query);
- }
- public function show_errors()
- {
- $this->show_errors = true;
- }
- public function hide_errors()
- {
- $this->show_errors = false;
- }
- public function flush()
- {
- $this->last_result = null;
- $this->col_info = null;
- $this->last_query = null;
- $this->from_disk_cache = false;
- }
- public function get_var($query = null, $x = 0, $y = 0)
- {
- $this->func_call = '$db->get_var("' . $query . '",' . $x . ',' . $y . ')';
- if ($query) {
- $this->query($query);
- }
- if ($this->last_result[$y]) {
- $values = array_values(get_object_vars($this->last_result[$y]));
- }
- return isset($values[$x]) && ($values[$x] !== '') ? $values[$x] : null;
- }
- public function set_prefix($table_prefix)
- {
- $this->prefix = $table_prefix;
- }
- public function get_row($query = null, $output = OBJECT, $y = 0)
- {
- $this->func_call = '$db->get_row("' . $query . '",' . $output . ',' . $y . ')';
- if ($query) {
- $this->query($query);
- }
- if ($output == OBJECT) {
- return $this->last_result[$y] ? $this->last_result[$y] : null;
- }
- if ($output == ARRAY_A) {
- return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null;
- }
- if ($output == ARRAY_N) {
- return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null;
- }
- $this->print_error(' $db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N');
- }
- public function get_col($query = null, $x = 0)
- {
- $new_array = array();
- if ($query) {
- $this->query($query);
- }
- $i = 0;
- while ($i < count($this->last_result)) {
- $new_array[$i] = $this->get_var(null, $x, $i);
- ++$i;
- }
- return $new_array;
- }
- public function get_results($query = null, $output = OBJECT)
- {
- $this->func_call = '$db->get_results("' . $query . '", ' . $output . ')';
- if ($query) {
- $this->query($query);
- }
- if ($output == OBJECT) {
- return $this->last_result;
- }
- if (($output == ARRAY_A) || ($output == ARRAY_N)) {
- if ($this->last_result) {
- $i = 0;
- foreach ($this->last_result as $row) {
- $new_array[$i] = get_object_vars($row);
- if ($output == ARRAY_N) {
- $new_array[$i] = array_values($new_array[$i]);
- }
- ++$i;
- }
- return $new_array;
- }
- return null;
- }
- }
- public function get_col_info($info_type = 'name', $col_offset = -1)
- {
- if ($this->col_info) {
- if ($col_offset == -1) {
- $i = 0;
- foreach ($this->col_info as $col) {
- $new_array[$i] = $col->{$info_type};
- ++$i;
- }
- return $new_array;
- }
- return $this->col_info[$col_offset]->{$info_type};
- }
- }
- public function store_cache($query, $is_insert)
- {
- $cache_file = $this->cache_dir . '/' . md5($query);
- if (($this->use_disk_cache && $this->cache_queries && !$is_insert) || ($this->cache_inserts && $is_insert)) {
- if (!is_dir($this->cache_dir)) {
- $this->register_error('Could not open cache dir: ' . $this->cache_dir);
- $this->show_errors ? trigger_error('Could not open cache dir: ' . $this->cache_dir, E_USER_WARNING) : null;
- return NULL;
- }
- $result_cache = array('col_info' => $this->col_info, 'last_result' => $this->last_result, 'num_rows' => $this->num_rows, 'return_value' => $this->num_rows);
- error_log(serialize($result_cache), 3, $cache_file);
- }
- }
- public function get_cache($query)
- {
- $cache_file = $this->cache_dir . '/' . md5($query);
- if ($this->use_disk_cache && file_exists($cache_file)) {
- if ($this->cache_timeout < (time() - filemtime($cache_file))) {
- unlink($cache_file);
- return NULL;
- }
- $result_cache = unserialize(file_get_contents($cache_file));
- $this->col_info = $result_cache['col_info'];
- $this->last_result = $result_cache['last_result'];
- $this->num_rows = $result_cache['num_rows'];
- $this->from_disk_cache = true;
- $this->trace || $this->debug_all ? $this->debug() : null;
- return $result_cache['return_value'];
- }
- }
- public function vardump($mixed = '')
- {
- ob_start();
- echo '<p><table><tr><td bgcolor=ffffff><blockquote><font color=000090>';
- echo '<pre><font face=arial>';
- if (!$this->vardump_called) {
- echo '<font color=800080><b>ezSQL</b> (v' . EZSQL_VERSION . ') <b>Variable Dump..</b></font>' . "\n\n";
- }
- $var_type = gettype($mixed);
- print_r($mixed ? $mixed : '<font color=red>No Value / False</font>');
- echo "\n\n" . '<b>Type:</b> ' . ucfirst($var_type) . "\n";
- echo '<b>Last Query</b> [' . $this->num_queries . ']<b>:</b> ' . ($this->last_query ? $this->last_query : 'NULL') . "\n";
- echo '<b>Last Function Call:</b> ' . ($this->func_call ? $this->func_call : 'None') . "\n";
- echo '<b>Last Rows Returned:</b> ' . count($this->last_result) . "\n";
- echo '</font></pre></font></blockquote></td></tr></table>' . $this->donation();
- echo "\n" . '<hr size=1 noshade color=dddddd>';
- $html = ob_get_contents();
- ob_end_clean();
- if ($this->debug_echo_is_on) {
- echo $html;
- }
- $this->vardump_called = true;
- return $html;
- }
- public function dumpvar($mixed)
- {
- $this->vardump($mixed);
- }
- public function debug($print_to_screen = true)
- {
- ob_start();
- echo '<blockquote>';
- if (!$this->debug_called) {
- echo '<font color=800080 face=arial size=2><b>ezSQL</b> (v' . EZSQL_VERSION . ') <b>Debug..</b></font><p>' . "\n";
- }
- if ($this->last_error) {
- echo '<font face=arial size=2 color=000099><b>Last Error --</b> [<font color=000000><b>' . $this->last_error . '</b></font>]<p>';
- }
- if ($this->from_disk_cache) {
- echo '<font face=arial size=2 color=000099><b>Results retrieved from disk cache</b></font><p>';
- }
- echo '<font face=arial size=2 color=000099><b>Query</b> [' . $this->num_queries . '] <b>--</b> ';
- echo '[<font color=000000><b>' . $this->last_query . '</b></font>]</font><p>';
- echo '<font face=arial size=2 color=000099><b>Query Result..</b></font>';
- echo '<blockquote>';
- if ($this->col_info) {
- echo '<table cellpadding=5 cellspacing=1 bgcolor=555555>';
- echo '<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>';
- $i = 0;
- while ($i < count($this->col_info)) {
- echo '<td nowrap align=left valign=top><font size=1 color=555599 face=arial>' . $this->col_info[$i]->type . ' ' . $this->col_info[$i]->max_length . '</font><br><span style=\'font-family: arial; font-size: 10pt; font-weight: bold;\'>' . $this->col_info[$i]->name . '</span></td>';
- ++$i;
- }
- echo '</tr>';
- if ($this->last_result) {
- $i = 0;
- foreach ($this->get_results(null, ARRAY_N) as $one_row) {
- ++$i;
- echo '<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>' . $i . '</font></td>';
- foreach ($one_row as $item) {
- echo '<td nowrap><font face=arial size=2>' . $item . '</font></td>';
- }
- echo '</tr>';
- }
- } else {
- echo '<tr bgcolor=ffffff><td colspan=' . (count($this->col_info) + 1) . '><font face=arial size=2>No Results</font></td></tr>';
- }
- echo '</table>';
- } else {
- echo '<font face=arial size=2>No Results</font>';
- }
- echo '</blockquote></blockquote>' . $this->donation() . '<hr noshade color=dddddd size=1>';
- $html = ob_get_contents();
- ob_end_clean();
- if ($this->debug_echo_is_on && $print_to_screen) {
- echo $html;
- }
- $this->debug_called = true;
- return $html;
- }
- public function donation()
- {
- return '<font size=1 face=arial color=000000>If ezSQL has helped <a href="https://www.paypal.com/xclick/business=justin%40justinvincent.com&item_name=ezSQL&no_note=1&tax=0" style="color: 0000CC;">make a donation!?</a> <!--[ go on! you know you want to! ]--></font>';
- }
- public function timer_get_cur()
- {
- list($usec, $sec) = explode(' ', microtime());
- return (double) $usec + (double) $sec;
- }
- public function timer_start($timer_name)
- {
- $this->timers[$timer_name] = $this->timer_get_cur();
- }
- public function timer_elapsed($timer_name)
- {
- return round($this->timer_get_cur() - $this->timers[$timer_name], 2);
- }
- public function timer_update_global($timer_name)
- {
- if ($this->do_profile) {
- $this->profile_times[] = array('query' => $this->last_query, 'time' => $this->timer_elapsed($timer_name));
- }
- $this->total_query_time += $this->timer_elapsed($timer_name);
- }
- public function get_set($parms)
- {
- $sql = '';
- foreach ($parms as $field => $val) {
- if ($val === 'true') {
- $val = 1;
- }
- if ($val === 'false') {
- $val = 0;
- }
- if ($val == 'NOW()') {
- $sql .= $field . ' = ' . $this->escape($val) . ', ';
- } else {
- $sql .= $field . ' = \'' . $this->escape($val) . '\', ';
- }
- }
- return substr($sql, 0, -2);
- }
- }
- class ezSQL_mysql extends ezSQLcore {
- public $dbuser = false;
- public $dbpassword = false;
- public $dbname = false;
- public $dbhost = false;
- public $prefix = '';
- public $trace = false;
- public $debug_all = false;
- public $debug_called = false;
- public $vardump_called = false;
- public $show_errors = true;
- public $num_queries = 0;
- public $last_query = null;
- public $last_error = null;
- public $col_info = null;
- public $captured_errors = array();
- public $cache_dir = false;
- public $cache_queries = false;
- public $cache_inserts = false;
- public $use_disk_cache = false;
- public $cache_timeout = 24;
- public $timers = array();
- public $total_query_time = 0;
- public $db_connect_time = 0;
- public $trace_log = array();
- public $use_trace_log = false;
- public $sql_log_file = false;
- public $do_profile = false;
- public $profile_times = array();
- public $field_types = array();
- public $real_escape = false;
- public $debug_echo_is_on = true;
- public function ezSQL_mysql($dbuser = '', $dbpassword = '', $dbname = '', $dbhost = 'localhost')
- {
- $this->dbuser = $dbuser;
- $this->dbpassword = $dbpassword;
- $this->dbname = $dbname;
- $this->dbhost = $dbhost;
- }
- public function quick_connect($dbuser = '', $dbpassword = '', $dbname = '', $dbhost = 'localhost')
- {
- $return_val = false;
- if (!$this->connect($dbuser, $dbpassword, $dbhost, true)) {
- } else if (!$this->select($dbname)) {
- } else {
- $return_val = true;
- }
- return $return_val;
- }
- public function connect($dbuser = '', $dbpassword = '', $dbhost = 'localhost')
- {
- global $ezsql_mysql_str;
- $return_val = false;
- if (!$dbuser) {
- $this->register_error($ezsql_mysql_str[1] . ' in ' . 'bilo.db.php' . ' on line ' . 659);
- $this->show_errors ? trigger_error($ezsql_mysql_str[1], E_USER_WARNING) : null;
- } else if (!$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true)) {
- $this->register_error($ezsql_mysql_str[2] . ' in ' . 'bilo.db.php' . ' on line ' . 665);
- $this->show_errors ? trigger_error($ezsql_mysql_str[2], E_USER_WARNING) : null;
- } else {
- $this->dbuser = $dbuser;
- $this->dbpassword = $dbpassword;
- $this->dbhost = $dbhost;
- $return_val = true;
- }
- return $return_val;
- }
- public function select($dbname = '')
- {
- global $ezsql_mysql_str;
- $return_val = false;
- if (!$dbname) {
- $this->register_error($ezsql_mysql_str[3] . ' in ' . 'bilo.db.php' . ' on line ' . 690);
- $this->show_errors ? trigger_error($ezsql_mysql_str[3], E_USER_WARNING) : null;
- } else if (!$this->dbh) {
- $this->register_error($ezsql_mysql_str[4] . ' in ' . 'bilo.db.php' . ' on line ' . 697);
- $this->show_errors ? trigger_error($ezsql_mysql_str[4], E_USER_WARNING) : null;
- } else if (!@mysql_select_db($dbname, $this->dbh)) {
- if (!($str = @mysql_error($this->dbh))) {
- $str = $ezsql_mysql_str[5];
- }
- $this->register_error($str . ' in ' . 'bilo.db.php' . ' on line ' . 708);
- $this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
- } else {
- $this->dbname = $dbname;
- $return_val = true;
- }
- return $return_val;
- }
- public function sysdate()
- {
- return 'NOW()';
- }
- public function query($query)
- {
- $return_val = 0;
- $this->flush();
- $query = trim($query);
- $this->func_call = '$db->query("' . $query . '")';
- $this->last_query = $query;
- $this->num_queries++;
- if ($cache = $this->get_cache($query)) {
- return $cache;
- }
- if (!isset($this->dbh) || !$this->dbh) {
- $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
- $this->select($this->dbname);
- }
- $this->result = @mysql_query($query, $this->dbh);
- if ($str = @mysql_error($this->dbh)) {
- $is_insert = true;
- $this->register_error($str);
- $this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
- return false;
- }
- $is_insert = false;
- if (preg_match('/^(insert|delete|update|replace)\\s+/i', $query)) {
- $this->rows_affected = @mysql_affected_rows();
- if (preg_match('/^(insert|replace)\\s+/i', $query)) {
- $this->insert_id = @mysql_insert_id($this->dbh);
- }
- $return_val = $this->rows_affected;
- } else {
- $i = 0;
- while ($i < @mysql_num_fields($this->result)) {
- $this->col_info[$i] = @mysql_fetch_field($this->result);
- ++$i;
- }
- $num_rows = 0;
- while ($row = @mysql_fetch_object($this->result)) {
- $this->last_result[$num_rows] = $row;
- ++$num_rows;
- }
- @mysql_free_result($this->result);
- $this->num_rows = $num_rows;
- $return_val = $this->num_rows;
- }
- $this->store_cache($query, $is_insert);
- $this->trace || $this->debug_all ? $this->debug() : null;
- return $return_val;
- }
- public function _weak_escape($string)
- {
- return addslashes($string);
- }
- public function _real_escape($string)
- {
- if ($this->dbh && $this->real_escape) {
- return mysql_real_escape_string($string, $this->dbh);
- }
- return addslashes($string);
- }
- public function _escape($data)
- {
- if (is_array($data)) {
- foreach ((array) $data as $k => $v) {
- if (is_array($v)) {
- $data[$k] = $this->_escape($v);
- } else {
- $data[$k] = $this->_real_escape($v);
- }
- }
- } else {
- $data = $this->_real_escape($data);
- }
- return $data;
- }
- public function escape($data)
- {
- if (is_array($data)) {
- foreach ((array) $data as $k => $v) {
- if (is_array($v)) {
- $data[$k] = $this->escape($v);
- } else {
- $data[$k] = $this->_weak_escape($v);
- }
- }
- } else {
- $data = $this->_weak_escape($data);
- }
- return $data;
- }
- public function escape_by_ref(&$string)
- {
- $string = $this->_real_escape($string);
- }
- public function prepare($query = null)
- {
- if (is_null($query)) {
- return NULL;
- }
- $args = func_get_args();
- array_shift($args);
- if (isset($args[0]) && is_array($args[0])) {
- $args = $args[0];
- }
- $query = str_replace('\'%s\'', '%s', $query);
- $query = str_replace('"%s"', '%s', $query);
- $query = preg_replace('|(?<!%)%s|', '\'%s\'', $query);
- array_walk($args, array($this, 'escape_by_ref'));
- return @vsprintf($query, $args);
- }
- public function insert($table, $data, $format = null)
- {
- return $this->_insert_replace_helper($table, $data, $format, 'INSERT');
- }
- public function replace($table, $data, $format = null)
- {
- return $this->_insert_replace_helper($table, $data, $format, 'REPLACE');
- }
- public function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT')
- {
- if (!in_array(strtoupper($type), array('REPLACE', 'INSERT'))) {
- return false;
- }
- $formats = $format = (array) $format;
- $fields = array_keys($data);
- $formatted_fields = array();
- foreach ($fields as $field) {
- if (!empty($format)) {
- $form = ($form = array_shift($formats) ? $form : $format[0]);
- } else if (isset($this->field_types[$field])) {
- $form = $this->field_types[$field];
- } else {
- $form = '%s';
- }
- $formatted_fields[] = $form;
- }
- $sql = $type . ' INTO `' . $table . '` (`' . implode('`,`', $fields) . '`) VALUES (\'' . implode('\',\'', $formatted_fields) . '\')';
- return $this->query($this->prepare($sql, $data));
- }
- public function update($table, $data, $where, $format = null, $where_format = null)
- {
- if (!is_array($data) || !is_array($where)) {
- return false;
- }
- $formats = $format = (array) $format;
- $bits = $wheres = array();
- foreach ((array) array_keys($data) as $field) {
- if (!empty($format)) {
- $form = ($form = array_shift($formats) ? $form : $format[0]);
- } else if (isset($this->field_types[$field])) {
- $form = $this->field_types[$field];
- } else {
- $form = '%s';
- }
- $bits[] = '`' . $field . '` = ' . $form;
- }
- $where_formats = $where_format = (array) $where_format;
- foreach ((array) array_keys($where) as $field) {
- if (!empty($where_format)) {
- $form = ($form = array_shift($where_formats) ? $form : $where_format[0]);
- } else if (isset($this->field_types[$field])) {
- $form = $this->field_types[$field];
- } else {
- $form = '%s';
- }
- $wheres[] = '`' . $field . '` = ' . $form;
- }
- $sql = 'UPDATE `' . $table . '` SET ' . implode(', ', $bits) . ' WHERE ' . implode(' AND ', $wheres);
- return $this->query($this->prepare($sql, array_merge(array_values($data), array_values($where))));
- }
- public function ezSQLcore()
- {
- }
- public function register_error($err_str)
- {
- $this->last_error = $err_str;
- $this->captured_errors[] = array('error_str' => $err_str, 'query' => $this->last_query);
- }
- public function show_errors()
- {
- $this->show_errors = true;
- }
- public function hide_errors()
- {
- $this->show_errors = false;
- }
- public function flush()
- {
- $this->last_result = null;
- $this->col_info = null;
- $this->last_query = null;
- $this->from_disk_cache = false;
- }
- public function get_var($query = null, $x = 0, $y = 0)
- {
- $this->func_call = '$db->get_var("' . $query . '",' . $x . ',' . $y . ')';
- if ($query) {
- $this->query($query);
- }
- if ($this->last_result[$y]) {
- $values = array_values(get_object_vars($this->last_result[$y]));
- }
- return isset($values[$x]) && ($values[$x] !== '') ? $values[$x] : null;
- }
- public function set_prefix($table_prefix)
- {
- $this->prefix = $table_prefix;
- }
- public function get_row($query = null, $output = OBJECT, $y = 0)
- {
- $this->func_call = '$db->get_row("' . $query . '",' . $output . ',' . $y . ')';
- if ($query) {
- $this->query($query);
- }
- if ($output == OBJECT) {
- return $this->last_result[$y] ? $this->last_result[$y] : null;
- }
- if ($output == ARRAY_A) {
- return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null;
- }
- if ($output == ARRAY_N) {
- return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null;
- }
- $this->print_error(' $db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N');
- }
- public function get_col($query = null, $x = 0)
- {
- $new_array = array();
- if ($query) {
- $this->query($query);
- }
- $i = 0;
- while ($i < count($this->last_result)) {
- $new_array[$i] = $this->get_var(null, $x, $i);
- ++$i;
- }
- return $new_array;
- }
- public function get_results($query = null, $output = OBJECT)
- {
- $this->func_call = '$db->get_results("' . $query . '", ' . $output . ')';
- if ($query) {
- $this->query($query);
- }
- if ($output == OBJECT) {
- return $this->last_result;
- }
- if (($output == ARRAY_A) || ($output == ARRAY_N)) {
- if ($this->last_result) {
- $i = 0;
- foreach ($this->last_result as $row) {
- $new_array[$i] = get_object_vars($row);
- if ($output == ARRAY_N) {
- $new_array[$i] = array_values($new_array[$i]);
- }
- ++$i;
- }
- return $new_array;
- }
- return null;
- }
- }
- public function get_col_info($info_type = 'name', $col_offset = -1)
- {
- if ($this->col_info) {
- if ($col_offset == -1) {
- $i = 0;
- foreach ($this->col_info as $col) {
- $new_array[$i] = $col->{$info_type};
- ++$i;
- }
- return $new_array;
- }
- return $this->col_info[$col_offset]->{$info_type};
- }
- }
- public function store_cache($query, $is_insert)
- {
- $cache_file = $this->cache_dir . '/' . md5($query);
- if (($this->use_disk_cache && $this->cache_queries && !$is_insert) || ($this->cache_inserts && $is_insert)) {
- if (!is_dir($this->cache_dir)) {
- $this->register_error('Could not open cache dir: ' . $this->cache_dir);
- $this->show_errors ? trigger_error('Could not open cache dir: ' . $this->cache_dir, E_USER_WARNING) : null;
- return NULL;
- }
- $result_cache = array('col_info' => $this->col_info, 'last_result' => $this->last_result, 'num_rows' => $this->num_rows, 'return_value' => $this->num_rows);
- error_log(serialize($result_cache), 3, $cache_file);
- }
- }
- public function get_cache($query)
- {
- $cache_file = $this->cache_dir . '/' . md5($query);
- if ($this->use_disk_cache && file_exists($cache_file)) {
- if ($this->cache_timeout < (time() - filemtime($cache_file))) {
- unlink($cache_file);
- return NULL;
- }
- $result_cache = unserialize(file_get_contents($cache_file));
- $this->col_info = $result_cache['col_info'];
- $this->last_result = $result_cache['last_result'];
- $this->num_rows = $result_cache['num_rows'];
- $this->from_disk_cache = true;
- $this->trace || $this->debug_all ? $this->debug() : null;
- return $result_cache['return_value'];
- }
- }
- public function vardump($mixed = '')
- {
- ob_start();
- echo '<p><table><tr><td bgcolor=ffffff><blockquote><font color=000090>';
- echo '<pre><font face=arial>';
- if (!$this->vardump_called) {
- echo '<font color=800080><b>ezSQL</b> (v' . EZSQL_VERSION . ') <b>Variable Dump..</b></font>' . "\n\n";
- }
- $var_type = gettype($mixed);
- print_r($mixed ? $mixed : '<font color=red>No Value / False</font>');
- echo "\n\n" . '<b>Type:</b> ' . ucfirst($var_type) . "\n";
- echo '<b>Last Query</b> [' . $this->num_queries . ']<b>:</b> ' . ($this->last_query ? $this->last_query : 'NULL') . "\n";
- echo '<b>Last Function Call:</b> ' . ($this->func_call ? $this->func_call : 'None') . "\n";
- echo '<b>Last Rows Returned:</b> ' . count($this->last_result) . "\n";
- echo '</font></pre></font></blockquote></td></tr></table>' . $this->donation();
- echo "\n" . '<hr size=1 noshade color=dddddd>';
- $html = ob_get_contents();
- ob_end_clean();
- if ($this->debug_echo_is_on) {
- echo $html;
- }
- $this->vardump_called = true;
- return $html;
- }
- public function dumpvar($mixed)
- {
- $this->vardump($mixed);
- }
- public function debug($print_to_screen = true)
- {
- ob_start();
- echo '<blockquote>';
- if (!$this->debug_called) {
- echo '<font color=800080 face=arial size=2><b>ezSQL</b> (v' . EZSQL_VERSION . ') <b>Debug..</b></font><p>' . "\n";
- }
- if ($this->last_error) {
- echo '<font face=arial size=2 color=000099><b>Last Error --</b> [<font color=000000><b>' . $this->last_error . '</b></font>]<p>';
- }
- if ($this->from_disk_cache) {
- echo '<font face=arial size=2 color=000099><b>Results retrieved from disk cache</b></font><p>';
- }
- echo '<font face=arial size=2 color=000099><b>Query</b> [' . $this->num_queries . '] <b>--</b> ';
- echo '[<font color=000000><b>' . $this->last_query . '</b></font>]</font><p>';
- echo '<font face=arial size=2 color=000099><b>Query Result..</b></font>';
- echo '<blockquote>';
- if ($this->col_info) {
- echo '<table cellpadding=5 cellspacing=1 bgcolor=555555>';
- echo '<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>';
- $i = 0;
- while ($i < count($this->col_info)) {
- echo '<td nowrap align=left valign=top><font size=1 color=555599 face=arial>' . $this->col_info[$i]->type . ' ' . $this->col_info[$i]->max_length . '</font><br><span style=\'font-family: arial; font-size: 10pt; font-weight: bold;\'>' . $this->col_info[$i]->name . '</span></td>';
- ++$i;
- }
- echo '</tr>';
- if ($this->last_result) {
- $i = 0;
- foreach ($this->get_results(null, ARRAY_N) as $one_row) {
- ++$i;
- echo '<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>' . $i . '</font></td>';
- foreach ($one_row as $item) {
- echo '<td nowrap><font face=arial size=2>' . $item . '</font></td>';
- }
- echo '</tr>';
- }
- } else {
- echo '<tr bgcolor=ffffff><td colspan=' . (count($this->col_info) + 1) . '><font face=arial size=2>No Results</font></td></tr>';
- }
- echo '</table>';
- } else {
- echo '<font face=arial size=2>No Results</font>';
- }
- echo '</blockquote></blockquote>' . $this->donation() . '<hr noshade color=dddddd size=1>';
- $html = ob_get_contents();
- ob_end_clean();
- if ($this->debug_echo_is_on && $print_to_screen) {
- echo $html;
- }
- $this->debug_called = true;
- return $html;
- }
- public function donation()
- {
- return '<font size=1 face=arial color=000000>If ezSQL has helped <a href="https://www.paypal.com/xclick/business=justin%40justinvincent.com&item_name=ezSQL&no_note=1&tax=0" style="color: 0000CC;">make a donation!?</a> <!--[ go on! you know you want to! ]--></font>';
- }
- public function timer_get_cur()
- {
- list($usec, $sec) = explode(' ', microtime());
- return (double) $usec + (double) $sec;
- }
- public function timer_start($timer_name)
- {
- $this->timers[$timer_name] = $this->timer_get_cur();
- }
- public function timer_elapsed($timer_name)
- {
- return round($this->timer_get_cur() - $this->timers[$timer_name], 2);
- }
- public function timer_update_global($timer_name)
- {
- if ($this->do_profile) {
- $this->profile_times[] = array('query' => $this->last_query, 'time' => $this->timer_elapsed($timer_name));
- }
- $this->total_query_time += $this->timer_elapsed($timer_name);
- }
- public function get_set($parms)
- {
- $sql = '';
- foreach ($parms as $field => $val) {
- if ($val === 'true') {
- $val = 1;
- }
- if ($val === 'false') {
- $val = 0;
- }
- if ($val == 'NOW()') {
- $sql .= $field . ' = ' . $this->escape($val) . ', ';
- } else {
- $sql .= $field . ' = \'' . $this->escape($val) . '\', ';
- }
- }
- return substr($sql, 0, -2);
- }
- }
- define('EZSQL_VERSION', '2.12');
- define('OBJECT', 'OBJECT', true);
- define('ARRAY_A', 'ARRAY_A', true);
- define('ARRAY_N', 'ARRAY_N', true);
- $ezsql_mysql_str = array(1 => 'Require $dbuser and $dbpassword to connect to a database server', 2 => 'Error establishing mySQL database connection. Correct user/password? Correct hostname? Database server running?', 3 => 'Require $dbname to select a database', 4 => 'mySQL database connection is not active', 5 => 'Unexpected error while trying to select database');
- if (!function_exists('mysql_connect')) {
- exit('<b>Fatal Error:</b> ezSQL_mysql requires mySQL Lib to be compiled and or linked in to the PHP engine');
- }
- if (!class_exists('ezSQLcore')) {
- exit('<b>Fatal Error:</b> ezSQL_mysql requires ezSQLcore (ez_sql_core.php) to be included/loaded before it can be used');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement