joelwan / php-object-generator

ORM class generator for PHP
http://www.phpobjectgenerator.com
29 stars 30 forks source link

using transactions #9

Closed Rafeethu closed 10 years ago

Rafeethu commented 12 years ago

hi Loksly, Joel

do you guys have any idea of using transactions in POG. i think we need to alter the save, delete methods to pass the connection so that we can commit or rollback if something goes wrong. again i'm worrying this will cause major issues.

any comments?

Rifky

Loksly commented 12 years ago

I've already studied that. I thought I would be better to add functions to Database class:

Database::startTransaction() Database::commit() Database::rollback()

so your code can use them. It's easier and I guess it doesn't break compatibility backwards.

Loksly commented 12 years ago

for example, something like this

public static function startTransaction() { $null = mysql_query("START TRANSACTION", self::Connect()); return mysql_query("BEGIN", self::Connect()); }

public static function commit(){ return mysql_query("COMMIT", self::Connect()); }

public static function rollback(){ return mysql_query("ROLLBACK", self::Connect()); }

Rafeethu commented 12 years ago

did you implemented this or still under planning?

Loksly commented 12 years ago

I've implemented for a project which uses pog, altering Database class for that project. I haven't updated pog project itself with this feature.

Loksly commented 12 years ago

/* I forgot to disable the autocommit */

public static function startTransaction() { $null = mysql_query("SET AUTOCOMMIT=0", self::Connect()); $null = mysql_query("START TRANSACTION", self::Connect()); return mysql_query("BEGIN", self::Connect()); }

Rafeethu commented 12 years ago

can you attach the modified database class so that i can have a look if you don't mind,

rgds Rifky

On Fri, May 4, 2012 at 12:37 PM, M Loksly < reply@reply.github.com

wrote:

/* I forgot to disable the autocommit */

public static function startTransaction() { $null = mysql_query("SET AUTOCOMMIT=0", self::Connect()); $null = mysql_query("START TRANSACTION", self::Connect()); return mysql_query("BEGIN", self::Connect()); }


Reply to this email directly or view it on GitHub:

https://github.com/joelwan/php-object-generator/issues/9#issuecomment-5505398

Loksly commented 12 years ago

debugsql is an special code for profiling queries. its included at the bottom of a php file where all the requests are processed. At the beginning of that file there is a check like this:

if (isset($_GET['profiling']) && intval($_GET['profiling'])==1){ Database::NonQuery('set profiling=1', Database::Connect()); Database::NonQuery('set profiling_history_size=100', Database::Connect()); }

then the request (whatever the user ask the web application to do) is accomplished. and at the end there is the code included in debugsql.php

This is how I can see how much time is spent in an sql execution and the kind of queries that are executed. It's not perfect but it's enough for me ;-)

Rafeethu commented 12 years ago

i'm sorry, but does this relate to db transaction and database class what we were discussing earlier?

rgds Rifky

Loksly commented 12 years ago

Database class i've sent with does.

The other file doesn't. I've sent that one too because it has some debugging info that cause my database class to store each query sentence.

You asked for the Database class which offers transactions methods. don't you?

El sábado 5 de mayo de 2012, Rifky escribió:

i'm sorry, but does this relate to db transaction and database class what we were discussing earlier?

rgds Rifky


Reply to this email directly or view it on GitHub:

https://github.com/joelwan/php-object-generator/issues/9#issuecomment-5528388


«...me dijo que un solista como yo cantando en un coro era un verdadero desperdicio y que él tenía por norma deshacerse de los desperdicios»

Rafeethu commented 12 years ago

sorry Loksly, i didnt see any attachments. how can i download the class files you have sent.

Loksly commented 12 years ago

I'm sorry. It's my fault, I answered using email and I thought attachments will appear at github, now I see they don't.

Here you have:

database class: http://pastebin.com/W9CDmn6r

debugcode: http://pastebin.com/uDQ8n3iL

Rafeethu commented 12 years ago

thanks loksly. i'll have a look.