API16

JTable/delete

From Joomla! Documentation

< API16:JTable
Revision as of 17:41, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Method to delete a row from the database table by primary key value. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JTable/delete|...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.

Description[edit]

Method to delete a row from the database table by primary key value.

[Edit Descripton]

Template:Description:JTable/delete

Syntax[edit]

delete($pk=null)
Parameter Name Default Value Description
$pk null An optional primary key value to delete. If not set the instance property value is used.

Returns[edit]

boolean True on success.

Defined in[edit]

libraries/joomla/database/table.php

Importing[edit]

jimport( 'joomla.database.table' );

Source Body[edit]

public function delete($pk = null)
{
        // Initialise variables.
        $k = $this->_tbl_key;
        $pk = (is_null($pk)) ? $this->$k : $pk;

        // If no primary key is given, return false.
        if ($pk === null) {
                return false;
        }

        // If tracking assets, remove the asset first.
        if ($this->_trackAssets) {
                // Get and the asset name.
                $this->$k       = $pk;
                $name           = $this->_getAssetName();
                $asset          = JTable::getInstance('Asset');
                if ($asset->loadByName($name)) {
                        if (!$asset->delete()) {
                                $this->setError($asset->getError());
                                return false;
                        }
                } else {
                        $this->setError($asset->getError());
                        return false;
                }
        }

        // Delete the row by primary key.
        $this->_db->setQuery(
                'DELETE FROM `'.$this->_tbl.'`' .
                ' WHERE `'.$this->_tbl_key.'` = '.$this->_db->quote($pk)
        );
        $this->_db->query();

        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                $this->setError($this->_db->getErrorMsg());
                return false;
        }

        return true;
}

[Edit See Also] Template:SeeAlso:JTable/delete

Examples[edit]

<CodeExamplesForm />