function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $this->persistency = $persistency; $this->user = $sqluser; $this->password = $sqlpassword; $this->dbname = $database; $this->server = $sqlserver; if ($this->persistency) { $this->db_connect_id = odbc_pconnect($this->server, "", ""); } else { $this->db_connect_id = odbc_connect($this->server, "", ""); } if ($this->db_connect_id) { @odbc_autocommit($this->db_connect_id, off); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $this->sql_time += $endtime - $starttime; return $this->db_connect_id; } else { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $this->sql_time += $endtime - $starttime; return false; } }
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $this->persistency = $persistency; $this->user = $sqluser; $this->password = $sqlpassword; $this->dbname = $database; $this->server = $sqlserver; if ($this->persistency) { $this->db_connect_id = odbc_pconnect($this->server, "", ""); } else { $this->db_connect_id = odbc_connect($this->server, "", ""); } if ($this->db_connect_id) { @odbc_autocommit($this->db_connect_id, off); return $this->db_connect_id; } else { return false; } }
/** * Connection to the database * */ public function __construct() { parent::__construct(); if ($this->table == '') { $this->table = $this->table_prefix . str_replace('Model', '', get_class($this)); } require FRAMEWORK . DS . 'conf' . DS . 'datastore.php'; $config = $datastore[$this->datastore]; if (!isset(self::$connection[$this->datastore])) { self::$connection[$this->datastore] = odbc_connect('DRIVER={SQL Server};SERVER=' . $config['host'] . ';DATABASE=' . $config['db'] . '', $config['user'], $config['password']); if (!self::$connection[$this->datastore]) { throw new connectException('Could not connect to the datastore: ' . odbc_errormsg()); } if (!odbc_autocommit(self::$connection[$this->datastore], false)) { throw new connectException('unable to connect: ' . odbc_errormsg()); } } $this->con =& self::$connection[$this->datastore]; }
/** * SQL Transaction * @access: private */ function _sql_transaction($status = 'begin') { switch ($status) { case 'begin': return @odbc_autocommit($this->db_connect_id, false); break; case 'commit': $result = @odbc_commit($this->db_connect_id); @odbc_autocommit($this->db_connect_id, true); return $result; break; case 'rollback': $result = @odbc_rollback($this->db_connect_id); @odbc_autocommit($this->db_connect_id, true); return $result; break; } return true; }
/** * Rollback Transaction. * * @return bool */ protected function _trans_rollback() { if (odbc_rollback($this->conn_id)) { odbc_autocommit($this->conn_id, true); return true; } return false; }
/** * Begin a transaction * * @param unknown_type $model * @return boolean True on success, false on fail * (i.e. if the database/model does not support transactions). */ function begin(&$model) { if (parent::begin($model)) { if (odbc_autocommit($this->connection, false)) { $this->_transactionStarted = true; return true; } } return false; }
/** * Rollback Transaction * * @return bool */ public function trans_rollback() { // When transactions are nested we only begin/commit/rollback the outermost ones if (!$this->trans_enabled or $this->_trans_depth > 0) { return TRUE; } $ret = odbc_rollback($this->conn_id); odbc_autocommit($this->conn_id, TRUE); return $ret; }
function RollbackTrans() { if ($this->transOff) { return true; } if ($this->transCnt) { $this->transCnt -= 1; } $this->_autocommit = true; $ret = odbc_rollback($this->_connectionID); odbc_autocommit($this->_connectionID, true); return $ret; }
/** * Rollback Transaction * * @return bool */ protected function _trans_rollback() { if (odbc_rollback($this->conn_id)) { odbc_autocommit($this->conn_id, TRUE); return TRUE; } return FALSE; }
# $Id$ # Sample PHP script accessing HyperSQL through the ODBC extension module. # (Therefore, you need to have the PHP ODBC module installed). # This test HyperSQL client uses the ODBC DSN "tstdsn" to connect up to a # HyperSQL server. Just configure your own DSN to use the HyperSQL ODBC # driver, specifying the HyperSQL server host name, database name, user, # password, etc. # Author: Blaine Simpson (blaine dot simpson at admc dot com) # Empty strings for the username or password parameter here will defer # to the ODBC manager for those values. I.e. the blanks here do not mean to # send blanks to the database server. $conn_id = odbc_connect('tstdsn', '', ''); if (!$conn_id) { exit('Connection Failed: ' . $conn_id . "\n"); } if (!odbc_autocommit($conn_id, FALSE)) { exit("Failed to turn off AutoCommit mode\n"); } if (!odbc_exec($conn_id, "DROP TABLE tsttbl IF EXISTS")) { exit("DROP command failed\n"); } if (!odbc_exec($conn_id, "CREATE TABLE tsttbl(\n id BIGINT generated BY DEFAULT AS IDENTITY,\n vc VARCHAR(20),\n entrytime TIMESTAMP DEFAULT current_timestamp NOT NULL\n)")) { exit("CREATE TABLE command failed\n"); } # First do a non-parameterized insert if (!odbc_exec($conn_id, "INSERT INTO tsttbl(id, vc) VALUES(1, 'one')")) { exit("Insertion of first row failed\n"); } # Now parameterized inserts $stmt = odbc_prepare($conn_id, "INSERT INTO tsttbl(id, vc) VALUES(?, ?)"); if (!$stmt) {
echo "resource? " . is_resource($r) . "\n"; if (!$r) { echo odbc_errormsg(); exit(1); } $rh = odbc_exec($r, "CREATE TABLE IF NOT EXISTS innotable ( idx INT UNSIGNED NOT NULL ) TYPE=InnoDB"); if ($rh == NULL) { echo odbc_errormsg($r); exit(1); } $rh = odbc_exec($r, "INSERT INTO innotable SET idx=300"); if ($rh == NULL) { echo odbc_errormsg($r); exit(1); } odbc_autocommit($r, false); $rh = odbc_exec($r, "INSERT INTO innotable SET idx=500"); if ($rh == NULL) { echo odbc_errormsg($r); exit(1); } odbc_rollback($r); $rh = odbc_exec($r, "SELECT * FROM innotable"); if ($rh == NULL) { echo odbc_errormsg($r); exit(1); } // fetch while ($rr = odbc_fetch_array($rh)) { var_dump($rr); }
/** * Is in transaction? * @return bool */ public function inTransaction() { return !odbc_autocommit($this->connection); }
function AutoCommitTransactions($auto_commit) { if (!$this->auto_commit == !$auto_commit) { return 1; } if (!isset($this->supported["Transactions"])) { return $this->SetError("Auto-commit transactions", "transactions are not supported"); } if ($this->connection && !@odbc_autocommit($this->connection, $auto_commit)) { return $this->SetODBCError("Auto-commit transactions", "Could not set transaction auto-commit mode to {$auto_commit}", $php_errormsg); } $this->auto_commit = $auto_commit; return 1; }
/** * Commit transaction and re-enable autocommit mode * * @throws VerticaException * @author Sergii Katrych <*****@*****.**> */ public function commit() { $result = odbc_commit($this->getConnection()); if (false === $result) { throw new VerticaException("Failed to commit transaction due to " . odbc_errormsg($this->getConnection()), odbc_error($this->getConnection())); } $result = odbc_autocommit($this->getConnection(), true); if (false === $result) { throw new VerticaException("Failed to re-enable autocommit to get out of transactions mode. " . odbc_errormsg($this->getConnection()), odbc_error($this->getConnection())); } }
<?php dirname(__FILE__); odbc_autocommit($this->conn_id, FALSE); session_set_save_handler($class, TRUE); substr(__FILE__, 0, 5); count($sql, true); echo 0, 1.1, false, CONSTANTE, ns\Name; print <<<HHH HHH; sprintf(<<<HHHH HHHH , $a); //dirname(__FILE__) => __DIR__
public function after_connect() { odbc_autocommit($this->_con, false); }
/** * End a transaction by either committing changes made, or reverting them */ public function endTransaction($commit) { if ($commit) { $result = $this->commit(); } else { $result = $this->rollback(); } switch ($this->mode) { case "mysql": if (!$this->server->autocommit(true)) { $result = false; } break; case "postgres": $result = $this->query("SET AUTOCOMMIT = ON"); break; case "redshift": # Do nothing, and use the result from the commit/rollback break; case "odbc": if (!odbc_autocommit($this->server, true)) { $result = false; } break; default: throw new \Exception("endTransaction() not supported in this mode (" . $this->mode . ")"); } if (!$result) { $this->error(); } $this->transaction = false; return true; }
public function autocommit($onOff) { odbc_autocommit($this->_lnk, $onOff); }
function RollbackTrans() { $ret = odbc_rollback($this->_connectionID); odbc_autocommit($this->_connectionID, true); return $ret; }
DibiDriverException(odbc_errormsg($this->connection).' '.odbc_error($this->connection));}odbc_autocommit($this->connection,TRUE);}function inTransaction(){return!odbc_autocommit($this->connection);}function
/** * Makes sure each database and extension handles BEGIN, COMMIT and ROLLBACK * * @param string &$sql The SQL to check for a transaction query * @param string $result_class The type of result object to create * @return mixed `FALSE` if normal processing should continue, otherwise an object of the type $result_class */ private function handleTransactionQueries(&$sql, $result_class) { // SQL Server supports transactions, but starts then with BEGIN TRANSACTION if ($this->type == 'mssql' && preg_match('#^\\s*(begin|start(\\s+transaction)?)\\s*#i', $sql)) { $sql = 'BEGIN TRANSACTION'; } $begin = FALSE; $commit = FALSE; $rollback = FALSE; // Track transactions since most databases don't support nesting if (preg_match('#^\\s*(begin|start)(\\s+(transaction|work))?\\s*$#iD', $sql)) { if ($this->inside_transaction) { throw new fProgrammerException('A transaction is already in progress'); } $this->inside_transaction = TRUE; $begin = TRUE; } elseif (preg_match('#^\\s*(commit)(\\s+(transaction|work))?\\s*$#iD', $sql)) { if (!$this->inside_transaction) { throw new fProgrammerException('There is no transaction in progress'); } $this->inside_transaction = FALSE; $commit = TRUE; } elseif (preg_match('#^\\s*(rollback)(\\s+(transaction|work))?\\s*$#iD', $sql)) { if (!$this->inside_transaction) { throw new fProgrammerException('There is no transaction in progress'); } $this->inside_transaction = FALSE; $rollback = TRUE; } if (!$begin && !$commit && !$rollback) { return FALSE; } // The PDO, OCI8, ODBC and SQLSRV extensions require special handling through methods and functions $is_pdo = $this->extension == 'pdo'; $is_oci = $this->extension == 'oci8'; $is_odbc = $this->extension == 'odbc'; $is_sqlsrv = $this->extension == 'sqlsrv'; if (!$is_pdo && !$is_oci && !$is_odbc && !$is_sqlsrv) { return FALSE; } // PDO seems to act weird if you try to start transactions through a normal query call if ($is_pdo) { try { $is_mssql = $this->type == 'mssql' && substr($this->database, 0, 4) != 'dsn:'; $is_oracle = $this->type == 'oracle' && substr($this->database, 0, 4) != 'dsn:'; if ($begin) { // The SQL Server PDO object hasn't implemented transactions if ($is_mssql) { $this->connection->exec('BEGIN TRANSACTION'); } elseif ($is_oracle) { $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); } else { $this->connection->beginTransaction(); } } elseif ($commit) { if ($is_mssql) { $this->connection->exec('COMMIT'); } elseif ($is_oracle) { $this->connection->exec('COMMIT'); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); } else { $this->connection->commit(); } } elseif ($rollback) { if ($is_mssql) { $this->connection->exec('ROLLBACK'); } elseif ($is_oracle) { $this->connection->exec('ROLLBACK'); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); } else { $this->connection->rollBack(); } } } catch (Exception $e) { $db_type_map = array('mssql' => 'MSSQL', 'mysql' => 'MySQL', 'oracle' => 'Oracle', 'postgresql' => 'PostgreSQL', 'sqlite' => 'SQLite'); throw new fSQLException('%1$s error (%2$s) in %3$s', $db_type_map[$this->type], $e->getMessage(), $sql); } } elseif ($is_oci) { if ($commit) { oci_commit($this->connection); } elseif ($rollback) { oci_rollback($this->connection); } } elseif ($is_odbc) { if ($begin) { odbc_autocommit($this->connection, FALSE); } elseif ($commit) { odbc_commit($this->connection); odbc_autocommit($this->connection, TRUE); } elseif ($rollback) { odbc_rollback($this->connection); odbc_autocommit($this->connection, TRUE); } } elseif ($is_sqlsrv) { if ($begin) { sqlsrv_begin_transaction($this->connection); } elseif ($commit) { sqlsrv_commit($this->connection); } elseif ($rollback) { sqlsrv_rollback($this->connection); } } $result = new $result_class($this); $result->setSQL($sql); $result->setResult(TRUE); return $result; }
/** * Roll back (undo) the current transaction. * @throws SQLException * @return void */ protected function rollbackTrans() { if ($this->adapter->supportsTransactions()) { $result = @odbc_rollback($this->dblink); if (!$result) { throw new SQLException('Could not rollback transaction', $this->nativeError()); } @odbc_autocommit($this->dblink, true); if (odbc_error($this->dblink) == 'S1C00') { throw new SQLException('Could not rollback transaction (autocommit failed)', $this->nativeError()); } } }
public function transCommit() { $commit = odbc_commit($this->connect); odbc_autocommit($this->connect, true); return $commit; }
/** * Rollback changes in a transaction. * @return void * @throws DibiDriverException */ public function rollback() { if (!odbc_rollback($this->connection)) { $this->throwException(); } odbc_autocommit($this->connection, TRUE); }
function sql_query($query = "", $transaction = FALSE) { if ($query != "") { $this->num_queries++; if ($transaction == BEGIN_TRANSACTION && !$this->in_transaction) { if (!odbc_autocommit($this->db_connect_id, false)) { return false; } $this->in_transaction = TRUE; } if (preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?\$/s", $query, $limits)) { $query = $limits[1]; if (!empty($limits[2])) { $row_offset = $limits[4] ? $limits[3] : ""; $num_rows = $limits[4] ? $limits[4] : $limits[3]; $query = "TOP " . ($row_offset + $num_rows) . $query; } $this->result = odbc_exec($this->db_connect_id, "SELECT {$query}"); if ($this->result) { if (empty($this->field_names[$this->result])) { for ($i = 1; $i < odbc_num_fields($this->result) + 1; $i++) { $this->field_names[$this->result][] = odbc_field_name($this->result, $i); $this->field_types[$this->result][] = odbc_field_type($this->result, $i); } } $this->current_row[$this->result] = 0; $this->result_rowset[$this->result] = array(); $row_outer = isset($row_offset) ? $row_offset + 1 : 1; $row_outer_max = isset($num_rows) ? $row_offset + $num_rows + 1 : 1000000000.0; $row_inner = 0; while (odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max) { for ($j = 0; $j < count($this->field_names[$this->result]); $j++) { $this->result_rowset[$this->result][$row_inner][$this->field_names[$this->result][$j]] = stripslashes(odbc_result($this->result, $j + 1)); } $row_outer++; $row_inner++; } $this->num_rows[$this->result] = count($this->result_rowset[$this->result]); } } else { if (eregi("^INSERT ", $query)) { $this->result = odbc_exec($this->db_connect_id, $query); if ($this->result) { $result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY"); if ($result_id) { if (odbc_fetch_row($result_id)) { $this->next_id[$this->db_connect_id] = odbc_result($result_id, 1); $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result); } } } } else { $this->result = odbc_exec($this->db_connect_id, $query); if ($this->result) { $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result); } } } if (!$this->result) { if ($this->in_transaction) { odbc_rollback($this->db_connect_id); odbc_autocommit($this->db_connect_id, true); $this->in_transaction = FALSE; } return false; } if ($transaction == END_TRANSACTION && $this->in_transaction) { $this->in_transaction = FALSE; if (!odbc_commit($this->db_connect_id)) { odbc_rollback($this->db_connect_id); odbc_autocommit($this->db_connect_id, true); return false; } odbc_autocommit($this->db_connect_id, true); } odbc_free_result($this->result); return $this->result; } else { if ($transaction == END_TRANSACTION && $this->in_transaction) { $this->in_transaction = FALSE; if (!@odbc_commit($this->db_connect_id)) { odbc_rollback($this->db_connect_id); odbc_autocommit($this->db_connect_id, true); return false; } odbc_autocommit($this->db_connect_id, true); } return true; } }
<?php include 'config.inc'; // connect $link = odbc_connect($dsn, $user, $pass) or die("Unable to connect"); // disable odbc_autocommit($link, false); // check behavior var_dump(odbc_autocommit($link)); // enable odbc_autocommit($link, true); // check behavior var_dump(odbc_autocommit($link)); odbc_close($link);
function autoCommit($onoff = false) { if (!@odbc_autocommit($this->connection, $onoff)) { return $this->odbcRaiseError(); } return DB_OK; }
function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @odbc_autocommit($this->db_connect_id, false); $this->transaction = true; break; case 'commit': $result = @odbc_commit($this->db_connect_id); @odbc_autocommit($this->db_connect_id, true); $this->transaction = false; if (!$result) { @odbc_rollback($this->db_connect_id); @odbc_autocommit($this->db_connect_id, true); } break; case 'rollback': $result = @odbc_rollback($this->db_connect_id); @odbc_autocommit($this->db_connect_id, true); $this->transaction = false; break; default: $result = true; } return $result; }
/** * Rollback changes in a transaction. * @param string optinal savepoint name * @return void * @throws DibiDriverException */ public function rollback($savepoint = NULL) { if (!odbc_rollback($this->connection)) { throw new DibiDriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } odbc_autocommit($this->connection, TRUE); }
/** * Executes given SQL statement. * * @param string $sql SQL statement * @return resource Result resource identifier * @access protected */ function _execute($sql) { switch ($sql) { case 'BEGIN': return odbc_autocommit($this->connection, false); case 'COMMIT': return odbc_commit($this->connection); case 'ROLLBACK': return odbc_rollback($this->connection); } // TODO: should flags be set? possible requirement: SQL_CURSOR_STATIC return odbc_exec($this->connection, $sql); }