00001 <?php
00011 class DB_MySQL extends DB_Base
00012 {
00013 function DB_MySQL($conn, $persistent) {
00014 $this->safesql = new SafeSQL_MySQL;
00015 $this->type = 'mysql';
00016
00017 if($persistent) {
00018 $this->conn = mysql_pconnect($conn['host'], $conn['user'], $conn['pass']);
00019 } else {
00020 $this->conn = mysql_connect($conn['host'], $conn['user'], $conn['pass']);
00021 }
00022
00023 if(!$this->conn) {
00024 $this->_catch("Unable to connect to the database!");
00025 return false;
00026 }
00027
00028 if(DB_MYSQL_ANSI_MODE !== false) {
00029
00030
00031 $this->run_query("SET SESSION sql_mode='ANSI'");
00032 }
00033
00034 $this->select($conn['name']);
00035 return true;
00036 }
00037
00038 function _catch($msg="") {
00039 if(!$this->error = mysql_error()) return true;
00040 $this->error($msg."<br>{$this->query}\n {$this->error}");
00041 }
00042
00043 function select($db) {
00044 mysql_select_db($db, $this->conn) or $this->_catch("Unable to connect to the database!");
00045 }
00046
00047 function get_table_defn($table) {
00048 return $this->get_all_pair("EXPLAIN \"$table\"");
00049 }
00050
00051 function run_query($sql) {
00052 return mysql_query($sql, $this->conn);
00053 }
00054
00055 function fetch_row(&$q, $free_result=false) {
00056 $a = mysql_fetch_array($q, MYSQL_NUM);
00057 if($free_result) mysql_free_result($q);
00058 return $a;
00059 }
00060
00061 function fetch_array(&$q, $free_result=false) {
00062 $a = mysql_fetch_array($q, MYSQL_ASSOC);
00063 if($free_result) mysql_free_result($q);
00064 return $a;
00065 }
00066
00067 function fetch_field(&$q, $num) {
00068 return mysql_fetch_field($q, $num);
00069 }
00070
00071 function num_fields(&$q) {
00072 return mysql_num_fields($q);
00073 }
00074
00075 function num_rows(&$q) {
00076 return mysql_num_rows($q);
00077 }
00078
00079 function get_insert_id() {
00080 return mysql_insert_id($this->conn);
00081 }
00082
00083 function free_result($q) {
00084 return @mysql_free_result($q);
00085 }
00086 }
00087
00088 ?>