Changeset a0f5395 for src/webservice/htdocs/SiWeather
- Timestamp:
- Aug 31, 2015, 11:01:21 PM (11 years ago)
- Branches:
- master
- Children:
- b5ebb8d
- Parents:
- 519df6e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php
r519df6e ra0f5395 35 35 $this->_database = null; 36 36 if(!$this->_config->dataDirectory()){ 37 $this->_lastErrorMessage = "No data directory set!"; 38 error_log("Could not connect to the database: "+ $this->lastErrorMessage()); 37 $this->setLastErrorMessage("Could not connect to the database: No data directory set!"); 39 38 $this->databaseFile = null; 40 39 } … … 61 60 } 62 61 62 public function lastDatabaseErrorMessage(){ 63 if(is_null($this->_database)) 64 return false; 65 return $this->_database->lastErrorMsg(); 66 } 67 68 public function lastInsertRowId(){ 69 if(is_null($this->_database)) 70 return -1; 71 return $this->_database->lastInsertRowID(); 72 } 73 63 74 public function connect() 64 75 { … … 67 78 } 68 79 if(is_null($this->_databaseFile) || empty($this->_databaseFile)){ 69 $this->_lastErrorMessage = "No database file given"; 70 error_log("Could not connect to the database: "+ $this->lastErrorMessage()); 80 $this->setLastErrorMessage("Could not connect to the database: No database file given"); 71 81 return false; 72 82 } … … 75 85 } 76 86 catch(\Exception $exception){ 77 $this->_lastErrorMessage = $exception->getMessage(); 78 error_log("Could not connect to the database: "+ $this->lastErrorMessage()); 87 $this->setLastErrorMessage("Could not connect to the database: "+ $exception->getMessage()); 79 88 return false; 80 89 } … … 82 91 $extension = $this->_config->getConfig("spatialiteExtension"); 83 92 if(empty($extension)){ 84 $this->_lastErrorMessage("No spatialiteExtension set!"); 85 error_log($this->lastErrorMessage()); 93 $this->setLastErrorMessage("No spatialiteExtension set!"); 86 94 return false; 87 95 } 88 96 if(!$db->loadExtension($extension)){ 89 $this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg(); 90 error_log($this->lastErrorMessage()); 97 $this->setLastErrorMessage("Could not load SpatialLite extension: ". $db->lastErrorMsg()); 91 98 return false; 92 99 } … … 104 111 return true; 105 112 } 106 $this->_lastErrorMessage = $this->_database->lastErrorMsg(); 107 error_log("Failed to close the database: "+ $this->lastErrorMessage()); 113 $this->setLastErrorMessage("Failed to close the database: "+ $this->_database->lastErrorMsg()); 108 114 return false; 109 115 } … … 117 123 return false; 118 124 } 119 return $this->_database->exec($query); 125 $result = $this->_database->exec($query); 126 if(!$result) 127 $this->setLastErrorMessage("Could not execute databae query \"". $query ."\": ". $this->_database->lastErrorMsg()); 128 return $result; 120 129 } 121 130 … … 128 137 return false; 129 138 } 130 return $this->_database->prepare($query); 139 $result = $this->_database->prepare($query); 140 if(!$result){ 141 error_log("logging"); 142 $this->setLastErrorMessage("Could not prepare database query \"". $query ."\": ". $this->_database->lastErrorMsg()); 143 } 144 return $result; 131 145 } 132 146 133 147 public function versionSpatialite(){ 134 148 if(is_null($this->_database)){ 135 $this-> _lastErrorMessage = "Unknown (No database connection)";149 $this->setLastErrorMessage("Unknown (No database connection)"); 136 150 return 0; 137 151 } … … 148 162 public function versionSqlite(){ 149 163 if(is_null($this->_database)){ 150 $this-> _lastErrorMessage = "Unknown (No database connection)";164 $this->setLastErrorMessage("Unknown (No database connection)"); 151 165 return 0; 152 166 } … … 160 174 return 0; 161 175 } 176 177 private function setLastErrorMessage($message){ 178 if(!empty($message)) 179 error_log($message); 180 $this->_lastErrorMessage = $message; 181 } 162 182 163 183 private $_database;
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)