From 4c8d3cd0499280095cabc5596bd16cedf3dfb021 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 8 Jun 2013 05:58:07 +0000 Subject: [PATCH] Fix the database class when a non standard path was used with the sqlite database. --- includes/classes/database.php | 59 ++--------------------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/includes/classes/database.php b/includes/classes/database.php index 358551db99..18e0e6c72d 100644 --- a/includes/classes/database.php +++ b/includes/classes/database.php @@ -89,67 +89,12 @@ include "root.php"; else { $db_name_short = $this->name; } - $this->path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; $this->path = realpath($this->path); if (file_exists($this->path.'/'.$this->name)) { - //echo "main file exists
"; + $this->db = new PDO('sqlite:'.$this->path.'/'.$this->name); //sqlite 3 } else { - $file_name = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/includes/install/sql/sqlite.sql'; - $file_contents = file_get_contents($file_name); - try { - //$db = new PDO('sqlite2:example.db'); //sqlite 2 - //$db = new PDO('sqlite::memory:'); //sqlite 3 - $db = new PDO('sqlite:'.$this->path.'/'.$this->name); //sqlite 3 - $db->beginTransaction(); - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } - - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $stringarray = explode("\n", $file_contents); - $x = 0; - foreach($stringarray as $sql) { - try { - $db->query($sql); - } - catch (PDOException $error) { - echo "error: " . $error->getMessage() . " sql: $sql
"; - } - $x++; - } - unset ($file_contents, $sql); - $db->commit(); - if (is_writable($this->path.'/'.$this->name)) { - //is writable - use database in current location - } - else { - //not writable - echo "The database ".$this->path."/".$this->name." is not writeable."; - exit; - } - } - try { - //$db = new PDO('sqlite2:example.db'); //sqlite 2 - //$db = new PDO('sqlite::memory:'); //sqlite 3 - $this->db = new PDO('sqlite:'.$this->path.'/'.$this->name); //sqlite 3 - - //add additional functions to SQLite so that they are accessible inside SQL - //bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] ) - $this->db->sqliteCreateFunction('md5', 'php_md5', 1); - $this->db->sqliteCreateFunction('unix_timestamp', 'php_unix_time_stamp', 1); - $this->db->sqliteCreateFunction('now', 'php_now', 0); - $this->db->sqliteCreateFunction('str_left', 'php_left', 2); - $this->db->sqliteCreateFunction('str_right', 'php_right', 2); - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); + echo "not found"; } }