Sybase SQL Anywhere:使用CodeIgniter回滚事务

I'm running CodeIgniter 2 with SQL Anywhere (I have a custom class to handle connection with SAP DLLs).

I have a problem with a transaction containing many queries. One of them is raising an error (returned by a trigger while trying to update a table) : in that case, I want the transaction to be rollbacked at the end of the treatment, as you can see below.

$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...'); //This raises an error
$this->db->trans_complete(); //A rollback is done, and should cancel the first query

I've tried to change following options :

  • chained => Off
  • continue_after_raiserror => On
  • on_tsql_error => Continue

What's weird is that I'm logging my queries : executing them manually in Interactive SQL works well ! It seems that the raised error breaks the transaction.

Could someone help me ?

Thanks

Finally I find the solution : we just need to use some functions provided by SAP PHP's DLLs (http://dcx.sap.com/index.html#sa160/en/dbprogramming/php-support.html).

  • begin transaction with :

    sasql_set_option($this->conn_id, 'auto_commit', 0);

  • finally, if you need to commit :

    sasql_commit($conn_id);

  • and if you need to rollback :

    sasql_rollback($conn_id); sasql_set_option($conn_id, 'auto_commit', 1);