/** * Create connection fybase * @param string $dns String connection for sybase * @param boolean $persistent Define connection for persistent */ function __construct($dns, $autocommit = true, $persistent = false) { $this->dns = $dns; $this->persistent = $persistent; $this->autocommit = $autocommit; if (!function_exists('sasql_connect')) { throw new Exception("SQL Anywhere model not install in this server!", 100); } // Verifica se a conexão é persistente if ($this->persistent) { $this->connection = sasql_pconnect($this->dns); } else { $this->connection = sasql_connect($this->dns); } if (!$this->connection) { throw new Exception("Connection Problem :: " . sasql_error(), 101); } // Define option auto_commit if ($this->connection) { sasql_set_option($this->connection, 'auto_commit', $this->autocommit ? 'on' : 0); $this->dbinfo = array($dns, $autocommit, $persistent); } }
/** * Begin Transaction * * @access public * @return bool */ function trans_begin($test_mode = FALSE) { if (!$this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. $this->_trans_failure = $test_mode === TRUE ? TRUE : FALSE; sasql_set_option($this->conn_id, 'auto_commit', 'on'); // DON'T KNOW THIS IS REQUIRED OR NOT. $this->simple_query('BEGIN TRANSACTION'); return TRUE; }
/** * Ends transactional mode and enables auto commit again. * * @throws SQLAnywhereException * * @return boolean Whether or not ending transactional mode succeeded. */ private function endTransaction() { if (!sasql_set_option($this->connection, 'auto_commit', 'on')) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } return true; }