< API16:JTable

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Method to load a row from the database by primary key and bind the fields to the JTable instance properties.


load($keys=null, $reset=true)
Parameter Name Default Value Description
$keys null An optional primary key value to load the row by, or an array of fields to match. If not set the instance property value is used.
$reset true True to reset the default values before loading the new row.


boolean True if successful. False if row not found or on error (internal error state set in that case).

Defined in



jimport( 'joomla.database.table' );

Source Body

public function load($keys = null, $reset = true)
        if (empty($keys))
                // If empty, use the value of the current key
                $keyName = $this->getKeyName();
                $keys = array($keyName => $this->$keyName);
        } else if (!is_array($keys)) {
                // Load by primary key.
                $keyName = $this->getKeyName();
                $keys = array($keyName => $keys);

        if ($reset) {

        // Initialise the query.
        $db             = $this->getDBO();
        $query  = $db->getQuery(true);
        $fields = array_keys($this->getProperties());

        foreach ($keys as $field => $value) {
                // Check that $field is in the table.
                if (!in_array($field, $fields)) {
                        $this->setError(JText::sprintf('JTable_Error_Class_is_missing_field', get_class($this), $field));
                        return false;
                // Add the search tuple to the query.
                $query->where($db->nameQuote($field).' = '.$db->quote($value));

        $row = $db->loadAssoc();

        // Check for a database error.
        if ($db->getErrorNum()) {
                return false;

        // Check that we have a result.
        if (empty($row)) {
                return false;

        // Bind the object with the row and return.
        return $this->bind($row);


Code Examples