multiple query insert

227 views
Skip to first unread message

faisal khan

unread,
Sep 4, 2012, 5:59:47 PM9/4/12
to joomla-de...@googlegroups.com
hi all 
how can i execute multiple insert statements the success of one depends on other

query1 = ' insert... table1';
query2 = ' insert... table2';
query3 = ' insert... table3';

if query1 = success then
          if query1 = success then
                      if query1 = success then

how to rollback or commit


thanks




Nick Savov

unread,
Sep 4, 2012, 6:48:08 PM9/4/12
to joomla-de...@googlegroups.com
Hi Faisal,

I'm guessing you could do use PHP conditional if/else statements with
mysql_result() since it returns FALSE on failure:
http://php.net/manual/en/function.mysql-result.php

Kind regards,
Nick
> --
> You received this message because you are subscribed to the Google Groups
> "Joomla! General Development" group.
> 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.
>
>

Niels Braczek

unread,
Sep 4, 2012, 8:35:50 PM9/4/12
to joomla-de...@googlegroups.com
Am 04.09.2012 23:59, schrieb faisal khan:

> how can i execute multiple insert statements the success of one depends on
> other

You're looking for transactions.

Regards,
Niels

--
| http://barcamp-wk.de · 2. Barcamp Westküste Frühjahr 2013 |
| http://www.bsds.de · BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
------------------------------------------------------------------

faisal khan

unread,
Sep 5, 2012, 3:53:31 PM9/5/12
to joomla-de...@googlegroups.com
yes i am looking for transactions.

faisal khan

unread,
Sep 5, 2012, 3:55:32 PM9/5/12
to joomla-de...@googlegroups.com
actually i am thing how this can be done using joomla database classes. like 
$db->query(query_sql)

Herman Peeren

unread,
Sep 5, 2012, 4:19:31 PM9/5/12
to joomla-de...@googlegroups.com
$db->query(query_sql) gives true on success. The rest (like eventually rollback) has to be programmed yourself, for there are no provisions for that in Joomla!.

I'm using Doctrine2 in Joomla! (yes, more to be published, working on it) and there you can do everything in memory and then "flush" the whole transaction to the database. But that still not the same as database operations with transactions and rollbacks.

In years of making custom webapplications, didn't really need it too. So maybe you should have a look at the design of your application: maybe you can avoid the need for transactions and especially for automated rollbacks. What is it that you want to accomplish?

Chris Davenport

unread,
Sep 5, 2012, 4:56:45 PM9/5/12
to joomla-de...@googlegroups.com
How about:

$db->transactionStart();
$db->query( $query1 );
$db->query( $query2 );
etc.
$db->transactionCommit(); or $db->transactionRollback();

Should work.

Chris.


--
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/-/9QIh4ibBGwYJ.

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.



--
Chris Davenport
Joomla Production Leadership Team

Herman Peeren

unread,
Sep 6, 2012, 2:58:38 AM9/6/12
to joomla-de...@googlegroups.com
Yes, indeed! Brilliant! I'm daily surprised by unexplored Joomla!-possibilities.Thank you!

Those transaction- and rollback-methods are not in the description of the API in appendix A of the "Mastering Joomla! 1.5... etc" book (James Kennard & Chuck Lanham, Packt Publishers), that's probably why I overlooked it. In Platform 11.4 those methods are in JDatabase and implemented in JDatabaseMySql (not in JDatabaseMySqli). In platform 12.1 they are in JDatabaseDriver and implemented in diverse concrete drivers.

See API documentation, a.o.:
More info for MySql: http://dev.mysql.com/doc/refman/5.1/en/commit.html
Maybe we can make a wiki-article about it (@sidd: would you mind writing a few lines about your application when it is finished?) .

Cheers,
Herman
Reply all
Reply to author
Forward
0 new messages