Public Member Functions | |
| Element () | |
| constructor | |
| set ($data) | |
| set data array | |
| get () | |
| get data array | |
| setDbTable ($AdbTable) | |
| set database table | |
| getDbTable () | |
| get name of database table | |
| setDbHandle ($AdbHandle) | |
| set database handle | |
| getDbHandle () | |
| get database handle | |
| queryDb ($query) | |
| send a query to the database without getting a result | |
| updateDb ($unique, $value) | |
| updates dataset where the unique database field matches a given value uses the private data variable of this class for input | |
| insertDb () | |
| inserts a new dataset uses the private data variable of this class for input the function examines $data and extracts the keys and the values and builds the query public | |
| getDbData ($unique, $value) | |
| get dataset from database where unique database field matches given value | |
| getDbDataByQuery ($query) | |
| get dataset from database using a given query | |
| getDbValueByQuery ($query, $field) | |
Data Fields | |
| $dbHandle | |
| $dbTable | |
| $data = array() | |
Definition at line 36 of file class.ilElement.php.
| ilElement::Element | ( | ) |
| ilElement::get | ( | ) |
get data array
Definition at line 83 of file class.ilElement.php.
{
// Has to be overwritten by object class
//return $this->data ;
}
| ilElement::getDbData | ( | $ | unique, | |
| $ | value | |||
| ) |
get dataset from database where unique database field matches given value
| string | $unique unique database field | |
| mixed | $value value for match |
Definition at line 277 of file class.ilElement.php.
References $q, $result, and getDbTable().
{
$this->checkDb("ilElement::getDbData()");
//check unique-key
if ($unique == "") {
die("ilElement::getDbData(): No unique database field given.");
}
//check value
if ($value == "") {
die("ilElement::getDbData(): No value given.");
}
//build query
$q = "SELECT * FROM " . $this->getDbTable() . " WHERE " . $unique . " = " . $this->dbHandle->quote($value);
$result = $this->dbHandle->query($q);
//check result
if (DB::isError($result)) {
die("ilElement::getDbData(): ".$result->getMessage());
}
//return an associative array from query or false
if ($result->numRows() > 0) {
return $result->fetchRow(DB_FETCHMODE_ASSOC);
} else {
return false;
}
} //end function getDbData
Here is the call graph for this function:| ilElement::getDbDataByQuery | ( | $ | query | ) |
get dataset from database using a given query
| string | $query query |
Definition at line 308 of file class.ilElement.php.
References $query, and $result.
{
//check database handle
if ($this->dbHandle == "") {
die("ilElement::getDbDataByQuery(): No database handle given.");
}
//check query
if ($query == "") {
die("ilElement::getDbDataByQuery(): No query given.");
}
//send query
$result = $this->dbHandle->query($query);
//analyze resultset
if (DB::isError($result)) {
die("ilElement::getDbDataByQuery(): ".$result->getMessage());
}
//return associative array or false
if ($result->numRows() > 0) {
return $result->fetchRow(DB_FETCHMODE_ASSOC);
} else {
return false;
}
} //end function getDbDataByQuery
| ilElement::getDbHandle | ( | ) |
get database handle
Definition at line 132 of file class.ilElement.php.
{
return $this->dbHandle;
}
| ilElement::getDbTable | ( | ) |
get name of database table
Definition at line 108 of file class.ilElement.php.
Referenced by getDbData().
{
return $this->dbTable;
}
Here is the caller graph for this function:| ilElement::getDbValueByQuery | ( | $ | query, | |
| $ | field | |||
| ) |
| string | ||
| string |
Definition at line 335 of file class.ilElement.php.
References $query, and $result.
{
//check database handle
if ($this->dbHandle == "") {
die("ilElement::getDbDataByQuery(): No database handle given.");
}
//check query
if ($query == "") {
die("ilElement::getDbDataByQuery(): No query given.");
}
$result = $this->dbHandle->query($query);
//analyze resultset
if (DB::isError($result)) {
die("ilElement::getDbValueByQuery(): ".$result->getMessage());
}
//return associative array or false
if ($result->numRows() > 0) {
$R = $result->fetchRow(DB_FETCHMODE_ASSOC);
return( $R[$field] );
} else {
return false;
}
}
| ilElement::insertDb | ( | ) |
inserts a new dataset uses the private data variable of this class for input the function examines $data and extracts the keys and the values and builds the query public
Definition at line 218 of file class.ilElement.php.
References $data, $fields, $q, and $result.
{
$this->checkDb("ilElement::insertDb()");
//check data
if (!is_array($this->data)) {
die("ilElement::insertDB(): No data given.");
}
//build query
$fields = "";
$values = "";
while (list($key, $val) = each($this->data)) {
$fields .= $key . ", ";
if (substr($val, 0, 9) == "password(") {
$val = trim($val);
$val= substr($val, 10);
$val = substr($val, 0, strlen($val) - 2);
$values .= "password(" . $this->dbHandle->quote($val . "") . "), ";
} else {
$values .= $this->dbHandle->quote($val . "") . ", ";
}
}
//check fields string
if ($fields == "") {
die("ilElement::insertDB(): No fields given.");
}
//check values-string
if ($values == "") {
die("ilElement::insertDB(): No values given.");
}
//truncate fields (there is a comma at the end...)
$fields = substr($fields, 0, strlen($fields)-2);
$values = substr($values, 0, strlen($values)-2);
$q = "INSERT INTO " . $this->dbTable . " (" . $fields . ") VALUES (" . $values . ")";
//evaluate result
$result = $this->dbHandle->query($q);
if (DB::isError($result)) {
die("ilElement::insertDb(): ".$result->getMessage()." : $q");
}
//query the unique-key of inserted dataset
$q = "SELECT LAST_INSERT_ID()";
$this->result = $this->dbHandle->query($q);
if (DB::isError($result)) {
die("ilElement::insertDb()-Last_ID: ".$result->getMessage());
}
//query the result
if ($data = $this->result->fetchRow()) {
return $data[0];
} else {
return(0);
}
} //end function insertDb
| ilElement::queryDb | ( | $ | query | ) |
send a query to the database without getting a result
| string | $query query |
Definition at line 142 of file class.ilElement.php.
| ilElement::set | ( | $ | data | ) |
set data array
| array | $data element data |
Definition at line 73 of file class.ilElement.php.
{
// Has to be overwritten by object class
//$this->data = $data;
}
| ilElement::setDbHandle | ( | $ | AdbHandle | ) |
set database handle
| string | database handle |
Definition at line 118 of file class.ilElement.php.
{
if ($AdbHandle == "") {
die("<b>Error: No Database handle given!</b><br>class: ".get_class($this)."<br>Script: ".__FILE__."<br>Line: ".__LINE__);
} else {
$this->dbHandle = $AdbHandle;
}
}
| ilElement::setDbTable | ( | $ | AdbTable | ) |
set database table
| string | database table |
Definition at line 94 of file class.ilElement.php.
{
if ($AdbTable == "") {
die("ilElement::setDbTable(): No database table given.");
} else {
$this->dbTable = $AdbTable;
}
}
| ilElement::updateDb | ( | $ | unique, | |
| $ | value | |||
| ) |
updates dataset where the unique database field matches a given value uses the private data variable of this class for input
| string | $unique unique database field | |
| mixed | $value value for match public |
Definition at line 164 of file class.ilElement.php.
{
$this->checkDb("ilElement::updateDb()");
//check unique
if ($unique == "") {
die("ilElement::updateDB(): No unique database field given.");
}
//check value
if ($value == "") {
die("ilElement::updateDB(): No value given.");
}
//check the private data-array
if (!is_array($this->data)) {
die("ilElement::updateDB(): No data given.");
}
//build query
$subq = "";
while (list($key, $val) = each($this->data)) {
if (substr($val, 0, 9) == "password(") {
$val = trim($val);
$val= substr($val, 10);
$val = substr($val, 0, strlen($val) - 2);
$subq .= $key. " = password(" . $this->dbHandle->quote($val . "") . "), ";
} else {
$subq .= $key . " = ". $this->dbHandle->quote($val) . ", ";
}
}
/* alt
while (list($key, $val) = each($this->data)) {
$subq .= $key . " = " . $this->dbHandle->quote($val) . ", ";
}
*/
//query is empty
if ($subq == "") {
die("ilElement::updateDB(): No data given.");
}
//truncate subq (there is a comma...)
$subq = substr($subq, 0, strlen($subq)-2);
//set query
$q = "UPDATE " . $this->dbTable . " SET " . $subq . " WHERE " . $unique . " = " . $this->dbHandle->quote($value);
$this->dbHandle->query($q);
//evaluate result
if (DB::isError($result)) {
die("ilElement::updateDb(): ".$result->getMessage()." : $q");
}
} //end function updateDb
| ilElement::$data = array() |
Definition at line 57 of file class.ilElement.php.
Referenced by insertDb().
| ilElement::$dbHandle |
Definition at line 43 of file class.ilElement.php.
| ilElement::$dbTable |
Definition at line 50 of file class.ilElement.php.
1.7.1