Jdatabase update if exists

905 views
Skip to first unread message

Rod Farrell

unread,
Jul 2, 2012, 5:14:59 AM7/2/12
to joomla-de...@googlegroups.com
Is there a jdatabase method for "update if record exists, otherwise insert new record"?


Rod Farrell
Websites With Purpose

ABN 95769808144
www.websiteswithpurpose.com.au

0414 909 759

~ Website Design ~ Website Development ~ SEO ~ Website Hosting ~ eCommerce ~

Confidentiality: This e-mail and its attachments are intended for the above name only and are confidential. If you are not the intended addressee, or the person responsible for delivering it to the intended addressee, you may not copy or deliver it to anyone else or use it in any unauthorised manner. To do so is prohibited and may be unlawful. If you receive this email by mistake, advise the sender immediately by using the reply facility in your email software.

David Swain

unread,
Jul 2, 2012, 8:07:42 AM7/2/12
to joomla-de...@googlegroups.com, rodfa...@xvdg.com
http://dev.mysql.com/doc/refman/5.0/en/replace.html
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

Mysql has "replace into <table> values <vals>" (which actually does delete then insert) or there's "insert ... on duplicate key update". Both of these are extensions to the sql standard which makes them interesting but not useful if your code needs to run everywhere that Joomla does (as Joomla now supports DBs other than MySQL).

If you need portability, I'd suggest either creating a stored procedure to do the check-insert/update, or modifying the db interface classes in Joomla by adding a "updateOrInsert" function that uses mysqls extensions there, and in the other(s) tries to select then runs an appropriate update / insert query*, or extending the JTable structure to make this work for your one or two tables . It really depends what scope you want this functionality and how in-depth you want to get.

:-Dave

* This idea not fully thought through, may be riddled with problems.

gopi gopi

unread,
Jul 2, 2012, 8:58:07 AM7/2/12
to joomla-de...@googlegroups.com
Hi,

 I just used for updating like this

                $db =& JFactory::getDBO();

                $order=$this->getorder($id); //here we need to get the id of the table row where we need to edit.

$order->order_status =$status; // order_status is the table field where i am updating my status using $status

$db->updateObject("#__orders_table", $order, "id"); //here it will be update, $order contains updating value 


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/YJ3XD2Ein_cJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.



--
Regards

Gopi.A



Reply all
Reply to author
Forward
0 new messages