Web Application: MySql Klassenreferenz Hauptseite Zusätzliche Informationen Datenstrukturen Klassenhierarchie Datenstrukturen file:///srv/www/vhosts/doxygen/class_my_sql.html Dateien Verzeichnisse Datenstruktur-Elemente MySql Klassenreferenz mys ql databas e c las s M ehr ... Öffentliche Methoden connect ($ dbA c c ount, $ admin) checkTable ($ dbField, $ dbI ndex, $ admin) truncateTable ($ table) addData ($ table, $ s qlFields , $ c ontent) selectData ($ query) deleteData ($ query) modif yData ($ query) real_escape_st ring ($ input) closeSql () Ausführliche Beschreibung provide all func tions to c onnec t to and work with MySql databas e A utor: M atthias P anc zyk (c ) 2 0 1 2 M atthias P anc zyk D efiniert in Zeile 11 der D atei MySql.php. Dokumentation der Elementfunktionen connect ( $ dbA ccount , $ admin ) c onnec t to mys ql databas e c onnec t to databas e and c reate databas e objec t if c onnec t not s uc c es s ful and admin true try to c reate databas e by c alling func tion c reateD atabas e Parameter: dbAccount array with information for databas e ac c es s admin bool if admin us er is ac tive Rückgabe: void databas e objec t if c onnec t s uc c es s ful, fals e if no c onnec tion D efiniert in Zeile 27 der D atei MySql.php. 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 { global $develop; $this->develop=$develop; $this->db=$dbAccount; $this->mySqli = @new mysqli($dbAccount["server"], $dbAccount["user"], $dbAccount["password"], $dbAccount["name"]); if ($this->mySqli->connect_errno != 0) { $ok=false; if ($admin) $ok=$this->createDatabase ($admin); else { $error = "ERROR: MySqli->connect: ".$this->mySqli->connect_errno. ' : ' .$this->mySqli->connect_error; if ($this->develop) error_log ($error); } if (!$ok) return false; } return true; } checkTable ( $ dbField, $ dbIndex, $ admin ) c hec k databas e table c hec k if databas e table is exis ting 1 von 4 18.09.2012 17:06 Web Application: MySql Klassenreferenz file:///srv/www/vhosts/doxygen/class_my_sql.html if not c reate table and indexes when needed Parameter: dbField array with databas e table fieldnames dbI ndex array with fields to produc e index admin bool true if admin us er Rückgabe: bool true if table is available, fals e if not D efiniert in Zeile 92 der D atei MySql.php. 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 { $error=""; $dbFields = ""; $query="SHOW TABLE STATUS LIKE '".$dbField[0]."'"; $result=$this->mySqli->query($query); if (($result->num_rows == 0) && ($admin)) { $result->close(); for ($i=2; $i<count($dbField); $i++) { $dbFields.=", ".$dbField[$i]; } //create table $query="CREATE TABLE ".$dbField[0]." ("; $query.=$dbField[1]." NOT NULL AUTO_INCREMENT, Primary KEY(".$dbIndex[0].")".$dbFields.")"; $result=$this->mySqli->query($query); if (!$result) { $error= "ERROR: MySqli->create table: ".$query; if ($this->develop) error_log ($error); } if (!$error && count($dbIndex)>1) { //if needed add additional index for ($i=1; $i<count($dbIndex); $i++) { $query="ALTER TABLE ".$dbField[0]." ADD INDEX ( ".$dbIndex[$i]." ) "; $result=$this->mySqli->query($query); if (!$result) { $error= "ERROR: MySqli->alter table: ".$query; if ($this->develop) error_log ($error); } } } } else $result->close(); if ($error) return false; return true; } truncateTable ( $ t able ) trunc ate databas e table trunc ate dababas e table Parameter: table s tring databas e table name Rückgabe: bool true if trunc ate s uc c es s ful, fals e if not Noch zu erledigen: need to c hange logic for tableRefill later in this projec t D efiniert in Zeile 136 der D atei MySql.php. 00137 00138 00139 00140 00141 00142 00143 00144 00145 { $query="TRUNCATE TABLE ".$table; if (!$this->mySqli->query ($query)) { $error= "ERROR: MySqli->truncate table: ".$query; if ($this->develop) error_log ($error); return false; } return true; } addData ( $ table, $ sqlFields, $ content 2 von 4 18.09.2012 17:06 Web Application: MySql Klassenreferenz file:///srv/www/vhosts/doxygen/class_my_sql.html ) add new entry to databas e table add new entry into databas e table Parameter: table s tring databas e table name s qlFields array fieldnames of databas e table content array with one datas ets to fill into table Rückgabe: bool true if entry added, fals e if not D efiniert in Zeile 155 der D atei MySql.php. 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 { $fields=""; foreach ($sqlFields as $f) $fields.=$f.", "; $fields=substr($fields,0,-2); if (!$content) $fieldsXML="\"\""; else { $fieldsXML="\"\",\""; foreach ($content as $c) $fieldsXML.=$c."\",\""; $fieldsXML=substr($fieldsXML,0,-2); } $query= "INSERT into ".$table."(".$fields.") VALUES (".$fieldsXML.")"; if (!$this->mySqli->query ($query)) { $error= "ERROR: MySqli->INSERT data: ".$this->mySqli->errno. ' : ' .$this->mySqli->error." ".$query; if ($this->develop) error_log ($error); return false; } return true; } selectData ( $ query ) s elec t entries from databas e table s elec t entries from databas e table by query Parameter: query s tring to s end to databas e Rückgabe: void if s elec t ok return datas et, fals e if query has failure D efiniert in Zeile 184 der D atei MySql.php. 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 { if (!$result=$this->mySqli->query ($query)) { $error= "ERROR: MySqli->select data: ".$this->mySqli->errno. ' : ' .$this->mySqli->error." ".$query; if ($this->develop) error_log ($error); return false; } $collect=false; $i=0; while ($test = $result->fetch_object()) { $collect[$i]=$test; $i++; } $result->close(); return $collect; } deleteData ( $ query ) delete entries from databas e table delete entries from databas e table by query Parameter: query s tring to s end to databas e Rückgabe: 3 von 4 18.09.2012 17:06 Web Application: MySql Klassenreferenz file:///srv/www/vhosts/doxygen/class_my_sql.html bool true if ok, fals e if query has failure D efiniert in Zeile 208 der D atei MySql.php. 00209 00210 00211 00212 00213 00214 00215 00216 { if (!$result=$this->mySqli->query ($query)) { $error= "ERROR: MySqli->delete data: ".$this->mySqli->errno. ' : ' .$this->mySqli->error." ".$query; if ($this->develop) error_log ($error); return false; } return true; } modif yData ( $ query ) modify entry from databas e table modify entry from databas e tablw Parameter: query s tring to s end to databas e Rückgabe: bool true if ok, fals e if query has failure D efiniert in Zeile 224 der D atei MySql.php. 00225 00226 00227 00228 00229 00230 00231 00232 { if (!$result=$this->mySqli->query ($query)) { $error= "ERROR: MySqli->modify data: ".$this->mySqli->errno. ' : ' .$this->mySqli->error." ".$query; if ($this->develop) error_log ($error); return false; } return true; } real_escape_string ( $ input ) c orrec t s tring to ens ure it c an be added to databas e c orrec t s tring to ens ure it c an be added to databas e Parameter: input s tring original s tring Rückgabe: s tring c orrec ted s tring for input into databas s e D efiniert in Zeile 240 der D atei MySql.php. 00241 00242 00243 closeSql ( { return $this->mySqli->real_escape_string($input); } ) c los e databas e c onnec tion D efiniert in Zeile 249 der D atei MySql.php. 00250 00251 00252 { $this->mySqli->close(); } D ie D okumentation für dies e Klas s e wurde erzeugt aufgrund der D atei: MySql.php 4 von 4 18.09.2012 17:06