API16:JTable/delete
From Joomla! Documentation
Description
Method to delete a row from the database table by primary key value.
Syntax
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
boolean True on success.
Defined in
libraries/joomla/database/table.php
Importing
jimport( 'joomla.database.table' );
Source Body
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;
}
Examples
Code Examples