Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00036 class ilElement {
00037
00043 var $dbHandle;
00044
00050 var $dbTable;
00051
00057 var $data = array();
00058
00063 function Element() {
00064
00065 }
00066
00073 function set($data) {
00074
00075
00076 }
00077
00083 function get() {
00084
00085
00086 }
00087
00094 function setDbTable($AdbTable) {
00095 if ($AdbTable == "") {
00096 die("ilElement::setDbTable(): No database table given.");
00097 } else {
00098 $this->dbTable = $AdbTable;
00099 }
00100 }
00101
00108 function getDbTable() {
00109 return $this->dbTable;
00110 }
00111
00118 function setDbHandle($AdbHandle) {
00119 if ($AdbHandle == "") {
00120 die("<b>Error: No Database handle given!</b><br>class: ".get_class($this)."<br>Script: ".__FILE__."<br>Line: ".__LINE__);
00121 } else {
00122 $this->dbHandle = $AdbHandle;
00123 }
00124 }
00125
00132 function getDbHandle() {
00133 return $this->dbHandle;
00134 }
00135
00142 function queryDb($query) {
00143 $this->checkDb("ilElement::queryDb()");
00144
00145 if ($query == "") {
00146 die("ilElement::queryDb(): No query given.");
00147 }
00148
00149 $result = $this->dbHandle->query($query);
00150 if (DB::isError($result)) {
00151 die("ilElement::queryDb(): ".$result->getMessage());
00152 }
00153
00154 return true;
00155 }
00156
00164 function updateDb($unique, $value) {
00165 $this->checkDb("ilElement::updateDb()");
00166
00167 if ($unique == "") {
00168 die("ilElement::updateDB(): No unique database field given.");
00169 }
00170
00171 if ($value == "") {
00172 die("ilElement::updateDB(): No value given.");
00173 }
00174
00175 if (!is_array($this->data)) {
00176 die("ilElement::updateDB(): No data given.");
00177 }
00178
00179 $subq = "";
00180 while (list($key, $val) = each($this->data)) {
00181 if (substr($val, 0, 9) == "password(") {
00182 $val = trim($val);
00183 $val= substr($val, 10);
00184 $val = substr($val, 0, strlen($val) - 2);
00185 $subq .= $key. " = password(" . $this->dbHandle->quote($val . "") . "), ";
00186 } else {
00187 $subq .= $key . " = ". $this->dbHandle->quote($val) . ", ";
00188 }
00189
00190 }
00191
00192
00193
00194
00195
00196
00197 if ($subq == "") {
00198 die("ilElement::updateDB(): No data given.");
00199 }
00200
00201 $subq = substr($subq, 0, strlen($subq)-2);
00202
00203 $q = "UPDATE " . $this->dbTable . " SET " . $subq . " WHERE " . $unique . " = " . $this->dbHandle->quote($value);
00204 $this->dbHandle->query($q);
00205
00206 if (DB::isError($result)) {
00207 die("ilElement::updateDb(): ".$result->getMessage()." : $q");
00208 }
00209 }
00210
00218 function insertDb() {
00219 $this->checkDb("ilElement::insertDb()");
00220
00221 if (!is_array($this->data)) {
00222 die("ilElement::insertDB(): No data given.");
00223 }
00224
00225 $fields = "";
00226 $values = "";
00227 while (list($key, $val) = each($this->data)) {
00228 $fields .= $key . ", ";
00229 if (substr($val, 0, 9) == "password(") {
00230 $val = trim($val);
00231 $val= substr($val, 10);
00232 $val = substr($val, 0, strlen($val) - 2);
00233 $values .= "password(" . $this->dbHandle->quote($val . "") . "), ";
00234 } else {
00235 $values .= $this->dbHandle->quote($val . "") . ", ";
00236 }
00237 }
00238
00239 if ($fields == "") {
00240 die("ilElement::insertDB(): No fields given.");
00241 }
00242
00243 if ($values == "") {
00244 die("ilElement::insertDB(): No values given.");
00245 }
00246
00247 $fields = substr($fields, 0, strlen($fields)-2);
00248 $values = substr($values, 0, strlen($values)-2);
00249 $q = "INSERT INTO " . $this->dbTable . " (" . $fields . ") VALUES (" . $values . ")";
00250
00251
00252 $result = $this->dbHandle->query($q);
00253 if (DB::isError($result)) {
00254 die("ilElement::insertDb(): ".$result->getMessage()." : $q");
00255 }
00256
00257 $q = "SELECT LAST_INSERT_ID()";
00258 $this->result = $this->dbHandle->query($q);
00259 if (DB::isError($result)) {
00260 die("ilElement::insertDb()-Last_ID: ".$result->getMessage());
00261 }
00262
00263 if ($data = $this->result->fetchRow()) {
00264 return $data[0];
00265 } else {
00266 return(0);
00267 }
00268 }
00269
00277 function getDbData($unique, $value) {
00278 $this->checkDb("ilElement::getDbData()");
00279
00280 if ($unique == "") {
00281 die("ilElement::getDbData(): No unique database field given.");
00282 }
00283
00284 if ($value == "") {
00285 die("ilElement::getDbData(): No value given.");
00286 }
00287
00288 $q = "SELECT * FROM " . $this->getDbTable() . " WHERE " . $unique . " = " . $this->dbHandle->quote($value);
00289 $result = $this->dbHandle->query($q);
00290
00291 if (DB::isError($result)) {
00292 die("ilElement::getDbData(): ".$result->getMessage());
00293 }
00294
00295 if ($result->numRows() > 0) {
00296 return $result->fetchRow(DB_FETCHMODE_ASSOC);
00297 } else {
00298 return false;
00299 }
00300 }
00301
00308 function getDbDataByQuery($query) {
00309
00310 if ($this->dbHandle == "") {
00311 die("ilElement::getDbDataByQuery(): No database handle given.");
00312 }
00313
00314 if ($query == "") {
00315 die("ilElement::getDbDataByQuery(): No query given.");
00316 }
00317
00318 $result = $this->dbHandle->query($query);
00319
00320 if (DB::isError($result)) {
00321 die("ilElement::getDbDataByQuery(): ".$result->getMessage());
00322 }
00323
00324 if ($result->numRows() > 0) {
00325 return $result->fetchRow(DB_FETCHMODE_ASSOC);
00326 } else {
00327 return false;
00328 }
00329 }
00330
00335 function getDbValueByQuery($query, $field) {
00336
00337 if ($this->dbHandle == "") {
00338 die("ilElement::getDbDataByQuery(): No database handle given.");
00339 }
00340
00341 if ($query == "") {
00342 die("ilElement::getDbDataByQuery(): No query given.");
00343 }
00344 $result = $this->dbHandle->query($query);
00345
00346 if (DB::isError($result)) {
00347 die("ilElement::getDbValueByQuery(): ".$result->getMessage());
00348 }
00349
00350 if ($result->numRows() > 0) {
00351 $R = $result->fetchRow(DB_FETCHMODE_ASSOC);
00352 return( $R[$field] );
00353 } else {
00354 return false;
00355 }
00356
00357 }
00358
00359 }
00360
00361 ?>