API15

API15:JDatabaseMySQLi/updateObject

From Joomla! Documentation

Revision as of 22:15, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Description <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </spa...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Description

[Edit Descripton]

Template:Description:JDatabaseMySQLi/updateObject

Syntax

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

Defined in

libraries/joomla/database/database/mysqli.php

Importing

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

Source Body

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] Template:SeeAlso:JDatabaseMySQLi/updateObject

Examples

<CodeExamplesForm />