API16:JDatabaseMySQL/updateObject
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Description
Description:JDatabaseMySQL/updateObject
Syntax
updateObject($table, &$object, $keyName, $updateNulls=true)
| Parameter Name | Default Value | Description |
|---|---|---|
| $table | $updateNulls | |
| &$object | ||
| $keyName | ||
| $updateNulls | true |
Defined in
libraries/joomla/database/database/mysql.php
Importing
jimport( 'joomla.database.database.mysql' );
Source Body
public function updateObject($table, &$object, $keyName, $updateNulls=true) { $fmtsql = 'UPDATE '.$this->nameQuote($table).' SET %s WHERE %s'; $tmp = array(); foreach (get_object_vars($object) as $k => $v) { if (is_array($v) or is_object($v) or $k[0] == '_') { // internal or NA field continue; } if ($k == $keyName) { // PK not to be updated $where = $keyName . '=' . $this->Quote($v); continue; } if ($v === null) { if ($updateNulls) { $val = 'NULL'; } else { continue; } } else { $val = $this->isQuoted($k) ? $this->Quote($v) : (int) $v; } $tmp[] = $this->nameQuote($k) . '=' . $val; } $this->setQuery(sprintf($fmtsql, implode(",", $tmp) , $where)); return $this->query(); }
[Edit See Also] SeeAlso:JDatabaseMySQL/updateObject
Examples
<CodeExamplesForm />
