Ver Mensaje Individual
  #4 (permalink)  
Antiguo 11/02/2007, 20:33
Avatar de deadlykyo
deadlykyo
 
Fecha de Ingreso: noviembre-2005
Ubicación: Cbba - Bolivia
Mensajes: 747
Antigüedad: 18 años, 5 meses
Puntos: 5
Re: transacciones en MySQL 4.1.21-standard

Si es un servidor de pago, tienes que hablar con el responsable tecnico y ver si es factible que te instalen la extensión de mysql que necesitas, ...
segun estuve leyendo la documentacion de mysql el api de PHP para mysql permite que ejecutes sentencias como BEGIN o START TRANSACTION, con el clasico mysql_query():
Código:
MySQL transactions

MySQL supports transactions on tables that are of type InnoDB. I have noticed a behaviour which is puzzling me when using transactions.

If I establish two connections within the same PHP page, start a transaction in the first connection and execute an INSERT query in the second one, and rollback the transaction in the first connection, the INSERT query in the second connection is also rolled-back.

I am assuming that a MySQL transaction is not bound by the connection within which it is set up, but rather by the PHP process that sets it up.

This is a very useful "mis-feature" (bug?) because it allows you to create something like this:

class Transaction {
  var $dbh;

  function Transaction($host, $username, $password) {
   $this->dbh = mysql_connect($host, $username, $password);
  }

  function _Transaction() {
     mysql_disconnect($this->dbh);
  }

  function begin() {
   mysql_query("BEGIN", $this->dbh);
  }

  function rollback() {
     mysql_query("ROLLBACK", $this->dbh);
  }

  function commit() {
   mysql_query("COMMIT", $this->dbh);
  }
}

which you could use to wrap around transactional statements like this:

$tx =& new Transaction("localhost", "username", "password");
$tx->begin();
$dbh = mysql_connect("localhost", "username", "password");
$result = mysql_query("INSERT ...");
if (!$result) {
  $tx->rollback();
} else {
  $tx->commit();
}
mysql_disconnect($dbh);
unset($tx);

The benefit of such a Transaction class is that it is generic and can wrap around any of your MySQL statements.
te dejo un ejemplo y un enlace a un articulo sobre el tema:
http://www.devarticles.com/c/a/MySQL...L-4.0-and-PHP/

saludos, cya
__________________
"El Conocimiento es de todos, no solo de algunos"

Última edición por deadlykyo; 11/02/2007 a las 20:57