00001 <?php
00011 class DB_SQLite extends DB_Base
00012 {
00013 function DB_SQLite($conn, $persistent) {
00014 $this->safesql = new SafeSQL_ANSI;
00015 $this->type = 'sqlite';
00016
00017 if($persistent) {
00018 $this->conn = sqlite_popen($conn['file']);
00019 } else {
00020 $this->conn = sqlite_open($conn['file']);
00021 }
00022
00023 if(!$this->conn) {
00024 $this->_catch("Unable to connect to the database!");
00025 return false;
00026 }
00027
00028 return true;
00029 }
00030
00031 function _catch($msg="") {
00032 if(!$this->error = sqlite_error_string(sqlite_last_error($this->conn))) return true;
00033 $this->error($msg."<br>{$this->query}\n {$this->error}");
00034 }
00035
00036 function get_table_defn($table) {
00037 if(PHP_VERSION < 5) return false;
00038
00039
00040 return sqlite_fetch_column_types($table, $this->conn, SQLITE_ASSOC);
00041 }
00042
00043 function run_query($sql) {
00044 return sqlite_query($sql, $this->conn);
00045 }
00046
00047 function fetch_row(&$q) {
00048 return sqlite_fetch_array($q, SQLITE_NUM);
00049 }
00050
00051 function fetch_array(&$q) {
00052 return sqlite_fetch_array($q, SQLITE_ASSOC);
00053 }
00054
00055 function fetch_field(&$q, $num) {
00056 $row = $this->fetch_row($q);
00057 return $row[$num];
00058 }
00059
00060 function num_fields(&$q) {
00061 return sqlite_num_fields($q);
00062 }
00063
00064 function num_rows(&$q) {
00065 return sqlite_num_rows($q);
00066 }
00067
00068 function get_insert_id() {
00069 return sqlite_last_insert_rowid($this->conn);
00070 }
00071
00072 function free_result($q) {
00073 return true;
00074 }
00075 }
00076
00077 ?>