How can write insert, update and delete query in joomla

for insert

$db            = & JFactory::getDBO();

$ins = new stdClass();
$ins->id = NULL;  // here id is auto increment id and primary key

$ins->table_field =$post[‘table_field’]; // table field name

…………………..

……………………..

if($db->insertObject(“jos_tablename”, $ins, ‘id’)){
unset($db);
}else{
echo $db->stderr();
}

for update

$ins->id = NULL;  // here id is  post/get retrieve value

$ins->table_field =$post[‘table_field’]; // table field name

…………………..

……………………..

if($db->updateObject(“jos_tablename”, $ins, ‘id’)){
unset($db);
}else{
echo $db->stderr();
}

foe delete

$db       =& JFactory::getDBO();
$query = ‘DELETE FROM jos_tablename’;
$db->setQuery( $query );
$db->query();

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s