本文整理汇总了PHP中PDO::inTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::inTransaction方法的具体用法?PHP PDO::inTransaction怎么用?PHP PDO::inTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::inTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inTransaction
/**
* Checks if inside a transaction
*
* @return bool
* @throws DatabaseException
*/
public function inTransaction() : bool
{
try {
return $this->pdo->inTransaction();
} catch (\PDOException $e) {
throw DatabaseException::pdoError($e->getMessage());
}
}
示例2: isTransactionRunning
public function isTransactionRunning()
{
if (method_exists($this->pdo, 'inTransaction')) {
return $this->pdo->inTransaction();
} else {
return parent::isTransactionRunning();
}
}
示例3: RollBack
/**
* @test
*/
public function RollBack()
{
$this->transaction->beginTransaction();
$rollBacked = $this->transaction->rollBack();
$this->assertTrue($rollBacked);
$this->assertFalse($this->pdo->inTransaction());
$this->assertFalse($this->transaction->isTransactionActive());
}
示例4: inTransaction
/**
* @see \herosphp\db\interfaces\Idb::inTransaction()
*/
public function inTransaction()
{
if ($this->link == null) {
$this->connect();
}
return $this->link->inTransaction();
}
示例5: install_schema
/**
Database install
*/
private static function install_schema()
{
$data = $_SESSION;
$sql = str_replace('[[now]]', time(), file_get_contents('assets/sql/anchor.sql'));
$dsn = 'mysql:dbname=' . $data['db']['name'] . ';host=' . $data['db']['host'] . ';port=' . $data['db']['port'];
$dbh = new PDO($dsn, $data['db']['user'], $data['db']['pass']);
try {
$dbh->beginTransaction();
$dbh->exec('SET NAMES `utf8`');
$dbh->exec($sql);
// create metadata
$sql = "INSERT INTO `meta` (`key`, `value`) VALUES ('sitename', ?), ('description', ?), ('theme', ?);";
$statement = $dbh->prepare($sql);
$statement->execute(array($data['site']['site_name'], $data['site']['site_description'], $data['site']['theme']));
// create user account
$sql = "INSERT INTO `users` (`username`, `password`, `email`, `real_name`, `bio`, `status`, `role`) VALUES (?, ?, ?, 'Administrator', 'Default account for Anchor.', 'active', 'administrator');";
$statement = $dbh->prepare($sql);
$statement->execute(array($data['user']['username'], crypt($data['user']['password'], $_SESSION['key']), $data['user']['email']));
$dbh->commit();
} catch (PDOException $e) {
Messages::add($e->getMessage());
// rollback any changes
if ($dbh->inTransaction()) {
$dbh->rollBack();
}
}
}
示例6: rollback
/**
* Rollback.
* Provides a fluent interface.
*
* @return PDOMySQL
*/
public function rollback()
{
if (isset($this->link) && $this->link->inTransaction()) {
$this->link->rollBack();
}
return $this;
}
示例7: inTransaction
public function inTransaction()
{
if (!$this->pdo) {
return false;
}
return $this->pdo->inTransaction();
}
示例8: executeQuery
function executeQuery($sqlCommand, $parameters)
{
try {
$connection = new PDO('mysql:dbname=circuito;host=localhost', 'root', '');
$command = $connection->prepare($sqlCommand);
if ($parameters != null) {
foreach ($parameters as $key => $value) {
$listaRetorno = array();
$command->bindValue($key, $value);
}
}
$command->execute();
$listaRetorno = array();
for ($i = 0; $row = $command->fetch(); $i++) {
array_push($listaRetorno, $row);
}
return $listaRetorno;
} catch (PDOException $ex) {
echo $ex->getTraceAsString();
if ($connection != null) {
if ($connection->inTransaction()) {
$connection->rollBack();
}
}
return array();
}
}
示例9: executeQuery
function executeQuery($sqlCommand, $parameters)
{
try {
$connection = new PDO('mysql:dbname=taller;host=localhost', 'root', 'mysql');
$command = $connection->prepare($sqlCommand);
if ($parameters != null) {
foreach ($parameters as $key => $value) {
$listaRetorno = array();
$command->bindValue($key, $value);
//echo $key."=>".$value."<br>";
}
}
$command->execute();
$listaRetorno = array();
for ($i = 0; $row = $command->fetch(PDO::FETCH_ASSOC); $i++) {
array_push($listaRetorno, $row);
}
return $listaRetorno;
} catch (PDOException $ex) {
echo $ex->getMessage();
if ($connection != null) {
if ($connection->inTransaction()) {
$connection->rollBack();
}
}
return array();
} finally {
//UTILIZADO NA VERSAO DO PHP 5.6 NAS PREVIAS NAO É COMPATÍVEL
if ($connection != null) {
//FECHA A CONEXAO COM O BANCO DE DADOS
$connection = null;
}
}
}
示例10: execute
/**
* Executes a prepared statement
*
* @param array $inputParams An array of values with as many elements as
* there are bound parameters in the SQL statement being executed.
* @throws \PDOException
* @return bool TRUE on success or FALSE on failure
*/
public function execute($inputParams = null)
{
$mode = OCI_COMMIT_ON_SUCCESS;
if ($this->_pdoOci8->inTransaction()) {
$mode = OCI_DEFAULT;
}
// Set up bound parameters, if passed in
if (is_array($inputParams)) {
foreach ($inputParams as $key => $value) {
$this->bindParam($key, $inputParams[$key]);
}
}
// The @ won't ignore the error in strict mode, so catch ErrorException
try {
$result = @oci_execute($this->_sth, $mode);
} catch (\ErrorException $e) {
$result = false;
}
if ($result != true) {
$e = $this->errorInfo();
$pdo_exception = new \PDOException($e[2], $e[1]);
$pdo_exception->errorInfo = $e;
throw $pdo_exception;
}
return $result;
}
示例11: rollback
public function rollback()
{
$this->transactionNestingLevel--;
if ($this->transactionNestingLevel == 0 && $this->db->inTransaction()) {
$this->db->rollBack();
}
}
示例12: rollbackTransaction
/**
* Rollsback a transaction
*
* @return bool true on success, false otherwise
*/
public function rollbackTransaction()
{
if (!$this->_connection->inTransaction()) {
return false;
}
return $this->_connection->rollback();
}
示例13: catchError
/**
* Almacena los errores
* @param string $error
*/
protected function catchError($error)
{
if ($this->connection->inTransaction()) {
$this->errorTran[] = $error;
$this->stateTran = FALSE;
}
$this->lastError = $error;
}
示例14: inTransaction
public function inTransaction()
{
if (!$this->isConnected) {
return false;
}
$this->connect();
return parent::inTransaction();
}
示例15: startTransaction
/**
* Starts a transaction
*
* @abstract
* @return void
*/
public function startTransaction()
{
if (!$this->pdoConnection->inTransaction()) {
if (!$this->pdoConnection->beginTransaction()) {
throw new RelationalSqlException("Unable to start transaction for unknown reasons");
}
return true;
}
return false;
}