Transaction in php script?

Author Message

Igor Vrdoljak

Wednesday 26 July 2006 3:27:47 am

Hi

I am working on a eZ solution which includes creation, update and deletion of eZ objects through SOAP web service methods. I intend to create methods which insert/update/delete multiple objects within one method call, so I need to put all that work into a single database transaction.

I am using eZ version 3.7.5, MySQL 4.1 with all tables converted to InnoDB, and transactions enabled in site.ini. Also, I use NuSOAP extension for developing web services.

Is there a simple way to put my PHP code into a single transaction. Something like:

START TRANSACTION;
...
... insert/update/delete code here
...
COMMIT TRANSACTION;

Thanx in advance.

http://www.netgen.hr/eng
http://twitter.com/ivrdoljak

Igor Vrdoljak

Wednesday 26 July 2006 4:31:43 am

This seems to work:

$db =& eZDB::instance();
$db->begin();

..
.. your code here
..

$db->commit();

http://www.netgen.hr/eng
http://twitter.com/ivrdoljak

Ɓukasz Serwatka

Wednesday 26 July 2006 4:32:27 am

Hi Igor,

Using eZ publish DB library (ezdb) you can use it like:

include_once( "lib/ezdb/classes/ezdb.php" );

$db =& eZDB::instance();
$db->begin();

//rest PHP code goes here

$db->commit();

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 21 2025 04:26:49
Script start
Timing: Jan 21 2025 04:26:49
Module start 'layout'
Timing: Jan 21 2025 04:26:49
Module start 'content'
Timing: Jan 21 2025 04:26:49
Module end 'content'
Timing: Jan 21 2025 04:26:49
Script end

Main resources:

Total runtime0.0153 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 587.9141151.2109
Module start 'layout' 0.00540.0043 739.125036.6484
Module start 'content' 0.00970.0043 775.773490.2656
Module end 'content' 0.01400.0013 866.039133.9922
Script end 0.0153  900.0313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002314.8824140.0002
Check MTime0.00116.8476140.0001
Mysql Total
Database connection0.00085.149310.0008
Mysqli_queries0.004126.629230.0014
Looping result0.00010.351210.0001
Template Total0.00116.910.0011
Template load0.00085.506710.0008
Template processing0.00021.336310.0002
Override
Cache load0.00053.270810.0005
General
dbfile0.00031.735680.0000
String conversion0.00000.077740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs