API16

JDatabaseMySQLi/loadObject: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== This global function loads the first row of a query into an object <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JDatabaseMySQLi/...
 
Sams (talk | contribs)
Added code example
Line 52: Line 52:


===Examples===
===Examples===
<source lang="php">
$db = &JFactory::getDBO();
$db->setQuery("SELECT * FROM #__categories");
$results = $db->loadArrayList();
</source>
<CodeExamplesForm />
<CodeExamplesForm />
<dpl>
<dpl>

Revision as of 19:28, 13 July 2010

Description

This global function loads the first row of a query into an object

[Edit Descripton]

Template:Description:JDatabaseMySQLi/loadObject

Syntax

loadObject($className= 'stdClass')
Parameter Name Default Value Description
$className 'stdClass' The name of the class to return (stdClass by default).

Returns

object

Defined in

libraries/joomla/database/database/mysqli.php

Importing

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

Source Body

public function loadObject($className = 'stdClass')
{
        if (!($cur = $this->query())) {
                return null;
        }
        $ret = null;
        if ($object = mysqli_fetch_object($cur, $className)) {
                $ret = $object;
        }
        mysqli_free_result($cur);
        return $ret;
}

[Edit See Also] Template:SeeAlso:JDatabaseMySQLi/loadObject

Examples

$db = &JFactory::getDBO();
$db->setQuery("SELECT * FROM #__categories");
$results = $db->loadArrayList();

<CodeExamplesForm />