X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot_db.php;h=585e5592d3ba70caae80411afe04cf2680a4c4c3;hp=96648be65cd09318180d2515d64bb13b18f2b247;hb=38599c2345c2cd49dec2e7ae25093cdb15eb5a23;hpb=61f2970e221f8612e51e7802cc127819c4caa369 diff --git a/phpfspot_db.php b/phpfspot_db.php index 96648be..585e559 100644 --- a/phpfspot_db.php +++ b/phpfspot_db.php @@ -101,7 +101,7 @@ class PHPFSPOT_DB { if($this->getConnStatus()) { if(($result = sqlite3_query($this->db, $query)) === false) - $this->trowError($this->getLastError()); + $this->ThrowError($this->getLastError()); return $result; } @@ -110,6 +110,24 @@ class PHPFSPOT_DB { } // db_query() + /** + * PHPFSPOT_DB database query & execute + * + * This function will execute a SQL query and return nothing. + */ + public function db_exec($query = "") + { + if($this->getConnStatus()) { + + if(($result = sqlite3_exec($this->db, $query)) === false) + $this->ThrowError($this->getLastError()); + + } + else + $this->ThrowError("Can't execute query - we are not connected!"); + + } // db_exec() + public function db_fetch_object(&$resource) { return sqlite3_fetch_array($resource); @@ -178,11 +196,10 @@ class PHPFSPOT_DB { public function db_check_table_exists($table_name = "") { if($this->getConnStatus()) { - $result = $this->db_query("SHOW TABLES"); - $tables_in = "Tables_in_". MYSQL_DB; - - while($row = $result->fetchRow()) { - if($row->$tables_in == $table_name) + + $result = $this->db_query("SELECT name FROM sqlite_master WHERE type='table'"); + while($table = $this->db_fetch_object($result)) { + if($table['name'] == $table_name) return true; } return false; @@ -237,8 +254,7 @@ class PHPFSPOT_DB { private function getLastError() { - - return sqlite3_error_string(sqlite3_last_error($this->db)); + return sqlite3_error($this->db); } // getLastError()