Actions

API16

JDatabaseMySQLi/updateObject

From Joomla! Documentation

< API16:JDatabaseMySQLi
Replacement filing cabinet.png
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

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

updateObject($table, &$object, $keyName, $updateNulls=true)
Parameter Name Default Value Description
$table $updateNulls
&$object
$keyName
$updateNulls true

Defined in

libraries/joomla/database/database/mysqli.php

Importing

jimport( 'joomla.database.database.mysqli' );

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();
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />