- Timestamp:
- Aug 26, 2015, 8:14:40 PM (11 years ago)
- Branches:
- master
- Children:
- b38cc03
- Parents:
- 8f38d1e
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php
r8f38d1e r8c356c1 19 19 */ 20 20 21 require_once("config/config.php");21 namespace SiWeather\Webservice; 22 22 23 23 /** … … 28 28 */ 29 29 class DatabaseHandler { 30 private $_database;31 private $_databaseFile;32 private $_lastErrorMessage;33 34 30 function __construct() 35 31 { 32 $this->_config = new WebserviceConfig(); 33 36 34 $this->_lastErrorMessage = ""; 37 35 $this->_database = null; 38 if(! getConfig("dataDirectory")){36 if(!$this->_config->dataDirectory()){ 39 37 $this->_lastErrorMessage = "No data directory set!"; 40 38 error_log("Could not connect to the database: "+ $this->lastErrorMessage()); … … 42 40 } 43 41 else{ 44 $this->_databaseFile = getConfig("dataDirectory") ."/siweather.sqlite";42 $this->_databaseFile = $this->_config->dataDirectory() ."/siweather.sqlite"; 45 43 } 46 44 } … … 66 64 { 67 65 if(!is_null($this->_database)){ 68 echo "database is not null";69 66 return true; 70 67 } … … 75 72 } 76 73 try { 77 $db = new SQLite3($this->_databaseFile);74 $db = new \SQLite3($this->_databaseFile); 78 75 } 79 76 catch(PDOException $exception){ … … 83 80 } 84 81 # loading SpatiaLite as an extension 85 if(!$db->loadExtension("libspatialite.so.7")){ 82 $extension = $this->_config->getConfig("spatialiteExtension"); 83 if(empty($extension)){ 84 $this->_lastErrorMessage("No spatialiteExtension set!"); 85 error_log($this->lastErrorMessage()); 86 return false; 87 } 88 if(!$db->loadExtension($extension)){ 86 89 $this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg(); 87 90 error_log($this->lastErrorMessage()); … … 105 108 return false; 106 109 } 110 111 public function exec($query) 112 { 113 if(!$this->connect()){ 114 return false; 115 } 116 return $this->_database->exec($query); 117 } 118 119 public function prepare($query) 120 { 121 if(!$this->connect()){ 122 return false; 123 } 124 return $this->_database->prepare($query); 125 } 126 127 public function versionSpatialite(){ 128 if(is_null($this->_database)){ 129 $this->_lastErrorMessage("Unknown (No database connection)"); 130 return 0; 131 } 132 if(!$this->connect()){ 133 return 0; 134 } 135 $result = $this->_database->query("SELECT spatialite_version()"); 136 while($row = $result->fetchArray()){ 137 return $row[0]; 138 } 139 return 0; 140 } 141 142 public function versionSqlite(){ 143 if(is_null($this->_database)){ 144 $this->_lastErrorMessage("Unknown (No database connection)"); 145 return 0; 146 } 147 if(!$this->connect()){ 148 return 0; 149 } 150 $result = $this->_database->query("SELECT sqlite_version()"); 151 while($row = $result->fetchArray()){ 152 return $row[0]; 153 } 154 return 0; 155 } 156 157 private $_database; 158 private $_databaseFile; 159 private $_lastErrorMessage; 160 private $_config; 107 161 } 108 162
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/siweather/chrome/site/your_project_logo.png)