当前位置: 首页>>代码示例>>PHP>>正文


PHP object::beginTransaction方法代码示例

本文整理汇总了PHP中object::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP object::beginTransaction方法的具体用法?PHP object::beginTransaction怎么用?PHP object::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object的用法示例。


在下文中一共展示了object::beginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beginTran

 public function beginTran()
 {
     echo "Beginning a transaction\n";
     if (!$this->db->beginTransaction()) {
         throw new \Exception('Beginning transaction failed');
     }
     return $this;
 }
开发者ID:awd-git,项目名称:Petshop,代码行数:8,代码来源:Data.php

示例2: __construct

 /**
  * Constructor
  *
  * @access public
  * @param  object  $pdo         PDO database object
  * @param  boolean $transaction Use database transactions [optional]
  * @param  boolean $sessionName Session name [optional]
  * @return void
  */
 public function __construct($pdo, $transaction = false, $sessionName = 'PDOSESSID')
 {
     // Set database connection
     $this->db = $pdo;
     if ($transaction) {
         $this->transaction = true;
         $this->db->beginTransaction();
     }
     // Start session
     session_set_save_handler(array(__CLASS__, '_open'), array(__CLASS__, '_close'), array(__CLASS__, '_read'), array(__CLASS__, '_write'), array(__CLASS__, '_destroy'), array(__CLASS__, '_gc'));
     session_name($sessionName);
     session_start();
 }
开发者ID:kaz6120,项目名称:Loggix,代码行数:22,代码来源:Session.php

示例3: beginTransaction

 /**
  * (non-PHPdoc)
  * @see PDO::beginTransaction()
  */
 public function beginTransaction()
 {
     if (!$this->pdo->inTransaction) {
         $this->pdo->beginTransaction();
     }
     return true;
 }
开发者ID:noikiy,项目名称:dophin,代码行数:11,代码来源:Mysql.class.php

示例4: startTrans

 /**
  * 开启事务处理
  *
  * @access public
  * @return boolean
  */
 public function startTrans()
 {
     if ($this->Transactions == false) {
         $this->db_link->beginTransaction();
         $this->Transactions = true;
     }
     return true;
 }
开发者ID:oohook,项目名称:PTFrameWork,代码行数:14,代码来源:pdo.php

示例5: begin_transaction

 /**
         This method begins the transaction
         @access public
  		@throws PDOException object
         @return void
 */
 public function begin_transaction()
 {
     try {
         if (!$this->DBHandler->inTransaction()) {
             $this->DBHandler->beginTransaction();
         }
     } catch (PDOException $e) {
         throw $e;
     }
 }
开发者ID:leandrocurioso,项目名称:php-restful-hmac,代码行数:16,代码来源:PDOHandler.class.php

示例6: startTrans

 /**
  * 开启事务处理
  *
  * @access public
  *
  * @return boolean
  */
 public function startTrans()
 {
     if ($this->_transactions == false) {
         $this->_dbLink->beginTransaction();
         $this->_transactions = true;
         //SQL日志记录
         $this->_logQuery('BEGIN');
     }
     return true;
 }
开发者ID:jinchunguang,项目名称:doitphp_standard_v3,代码行数:17,代码来源:DbPdo.php

示例7: beginTransaction

 public static function beginTransaction()
 {
     try {
         if (!self::$instance instanceof \PDO) {
             throw new \PDOException(self::$exception['no-instance']);
         }
         if (!self::$instance->beginTransaction()) {
             throw new \PDOException(current(self::$instance->errorInfo()) . ' ' . end(self::$instance->errorInfo()));
         }
     } catch (\PDOException $e) {
         self::stackTrace($e);
     }
 }
开发者ID:giovanniramos,项目名称:pdo4you,代码行数:13,代码来源:PDO4You.php

示例8: beginTransaction

 /**
  * Initiates a transaction
  * 
  * @return	boolean
  */
 public function beginTransaction()
 {
     if ($this->supportTransaction == false) {
         throw new LikePDOException("This driver doesn't support transactions");
         return false;
     } elseif ($this->inTransaction == true) {
         throw new LikePDOException("There is already an active transaction");
         return false;
     } else {
         if (!$this->driver->beginTransaction()) {
             throw new LikePDOException("Failed to begin transaction");
             return false;
         }
         return true;
     }
 }
开发者ID:erickmcarvalho,项目名称:likepdo,代码行数:21,代码来源:LikePDO.php

示例9: write

 /**
  * Write data associated with a given unique ID to container
  *
  * @access public
  * @param  string  $uniqueId  IP address or other unique ID.
  * @param  array   $data      The data associated with a given unique ID.
  * @return void
  * @throws HTTP_FloodControl_Exception if an error occured during writing process.
  */
 public function write($uniqueId, $data)
 {
     $quotedTblName = $this->_db->quoteIdentifier($this->_options['table']);
     $this->_db->beginTransaction();
     $query = sprintf("DELETE FROM %s WHERE unique_id = %s", $quotedTblName, $this->_db->quote($uniqueId, 'text'));
     $result = $this->_db->exec($query);
     if (PEAR::isError($result)) {
         throw new HTTP_FloodControl_Exception($result->getMessage(), $result->getCode());
     }
     $query = sprintf("INSERT INTO %s (unique_id, data, access) VALUES (%s, %s, %d)", $quotedTblName, $this->_db->quote($uniqueId, 'text'), $this->_db->quote(serialize($data), 'text'), time());
     $result = $this->_db->exec($query);
     if (PEAR::isError($result)) {
         $this->_db->rollback();
         throw new HTTP_FloodControl_Exception($result->getMessage(), $result->getCode());
     }
     $this->_db->commit();
 }
开发者ID:manishkhanchandani,项目名称:mkgxy,代码行数:26,代码来源:MDB2.php

示例10: flushWriteCache

 /**
  * Flush the write cache to db
  *
  * @access public
  */
 public function flushWriteCache()
 {
     if ($this->writeCacheData !== null) {
         $trans = $this->db->beginTransaction();
         /** can't create a prepared sql because some parameters can be null ??? */
         foreach ($this->writeCacheData as $key1 => $value1) {
             foreach ($value1 as $key2 => $value) {
                 $fields = array('do_id' => $this->absOrNull($this->do_id), 'app_id' => $this->absOrNull($this->app_id), 'us_id' => $this->absOrNull($this->us_id), 'se_section' => $key1, 'se_param' => $key2);
                 $sql = "UPDATE " . $this->options['settings_table'] . " SET \n" . "  se_value = " . $this->db->quote($this->writeCacheData[$key1][$key2]) . " \n" . "WHERE \n" . $this->array2Where($fields);
                 $affectedRows = $this->db->exec($sql);
                 $this->checkDBError($affectedRows, __LINE__);
                 if ($affectedRows == 0) {
                     $sql = "INSERT INTO " . $this->options['settings_table'] . " " . "  (do_id, app_id, us_id,se_section, se_param, se_value) " . "VALUES " . "  (" . $this->db->quote($this->absOrNull($this->do_id)) . ", " . $this->db->quote($this->absOrNull($this->app_id)) . ", " . $this->db->quote($this->absOrNull($this->us_id)) . ", " . $this->db->quote($key1) . ", " . $this->db->quote($key2) . ", " . $this->db->quote($this->writeCacheData[$key1][$key2]) . ")";
                     $res = $this->db->exec($sql);
                     $this->checkDBError($res, __LINE__);
                 }
             }
         }
         $trans = $this->db->commit();
         $this->writeCacheData = null;
     }
 }
开发者ID:r3-gis,项目名称:EcoGIS,代码行数:27,代码来源:r3dbini.php

示例11: transStart

 /**
  * Rozpoczęcie głównego bloku transakcji: DB->StartTrans()
  *
  * 1. Bloki transakcji można zagnieżdzać, ale nie jest wtedy uruchamiana nowa transakcja.
  * Inkrementowana jest jedynie wartość $this->transOff.
  * Podczas wywoływania CompleteTrans() wartość $this->transOff jest pomniejszana o 1.
  *
  * 2. Dopóki nie uruchomimy metody CompleteTrans(), to cała zawartość bloku będzie
  * uruchomiona z domyślnym Rollback-iem (sekwencje zostaną "przebite",
  * ale operacje na wierszach zostaną przywrócone).
  *
  * 3. Pomiędzy StartTrans() a CompleteTrans() metody BeginTrans/CommitTrans/RollbackTrans
  * zostaną zablokowane (nieaktywne).
  *
  * 4. Wywołanie metody CompleteTrans() śledzi błędy, więc jeśli wystąpił jakiś błąd SQL
  * lub została wywołana wcześniej metoda FailTrans(), to zostanie uruchomiony ROLLBACK.
  *
  * @throws MK_Db_Exception
  * @return bool
  */
 public function transStart()
 {
     // Zwrócenie szczegółowego komunikatu w konsoli FireBug-a
     if (MK_DEBUG_FIREPHP) {
         $this->fireBugSqlDump("transStart");
     }
     if (MK_Db_PDO_Singleton::transCount() > 0) {
         MK_Db_PDO_Singleton::transCount(1);
         return true;
     }
     /**
      *   true  - transakcja została utworzona
      *   false - baza danych nie obsługuje transakcji
      */
     MK_Db_PDO_Singleton::transOk(false);
     $transOk = $this->db->beginTransaction();
     if (!$transOk) {
         throw new MK_Db_Exception('Baza danych nie obsługuje transakcji');
     }
     MK_Db_PDO_Singleton::transOk(true);
     MK_Db_PDO_Singleton::transCount(1, true);
     return $transOk;
 }
开发者ID:b091,项目名称:mkphp-1,代码行数:43,代码来源:PDO.php

示例12: deleteNode

 /**
  * Delete a node and it's children
  *
  * @param int $keyValue Primary key of node
  * @return bool If it happend or not
  */
 public function deleteNode($keyValue)
 {
     try {
         $this->_pdoInstance->beginTransaction();
         $this->_lockTables();
         $node = $this->getSimpleNode($keyValue);
         // Delete the node
         $deleteSql = "DELETE FROM `" . $this->getTable() . "`\n                          WHERE\n                              `" . $this->getLeftColumn() . "`\n                                  BETWEEN '" . $node[$this->getLeftColumn()] . "'\n                                  AND '" . $node[$this->getRightColumn()] . "'";
         $this->_pdoInstance->exec($deleteSql);
         // Update left values of other nodes
         $updateSql = "UPDATE `" . $this->getTable() . "`\n                          SET `" . $this->getLeftColumn() . "` = `" . $this->getLeftColumn() . "` - ROUND(\n                              ('" . $node[$this->getRightColumn()] . "' - '" . $node[$this->getLeftColumn()] . "' + 1)\n                          )\n                          WHERE `" . $this->getLeftColumn() . "` > '" . $node[$this->getRightColumn()] . "'";
         $this->_pdoInstance->exec($updateSql);
         // Update right values of other nodes
         $updateSql = "UPDATE `" . $this->getTable() . "`\n                          SET `" . $this->getRightColumn() . "` = `" . $this->getRightColumn() . "` - ROUND(\n                              ('" . $node[$this->getRightColumn()] . "' - '" . $node[$this->getLeftColumn()] . "' + 1)\n                          )\n                          WHERE `" . $this->getRightColumn() . "` > '" . $node[$this->getRightColumn()] . "'";
         $this->_pdoInstance->exec($updateSql);
         $this->_pdoInstance->exec("UNLOCK TABLES");
         $this->_pdoInstance->commit();
         return true;
     } catch (\PDOException $e) {
         $this->_pdoInstance->rollBack();
         return false;
     }
 }
开发者ID:spiritix,项目名称:nested-set,代码行数:29,代码来源:NestedSet.php

示例13: DeleteAll

 /**
  * Delete element with number $ID from the tree and all it childret.
  *
  * @param integer $ID Number of element
  * @param array $condition Array structure: array('and' => array('id = 0', 'id2 >= 3'), 'or' => array('sec = \'www\'', 'sec2 <> \'erere\'')), etc where array key - condition (AND, OR, etc), value - condition string
  * @return bool TRUE if successful, FALSE otherwise.
  */
 function DeleteAll($ID, $condition = '')
 {
     $node_info = $this->GetNodeInfo($ID);
     if (FALSE === $node_info) {
         return FALSE;
     }
     list($leftId, $rightId) = $node_info;
     if (!empty($condition)) {
         $condition = $this->_PrepareCondition($condition);
     }
     $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $this->table_left . ' BETWEEN ' . $leftId . ' AND ' . $rightId;
     $this->db->beginTransaction();
     try {
         $res = $this->db->query($sql);
         $deltaId = $rightId - $leftId + 1;
         $sql = 'UPDATE ' . $this->table . ' SET ' . $this->table_left . ' = CASE WHEN ' . $this->table_left . ' > ' . $leftId . ' THEN ' . $this->table_left . ' - ' . $deltaId . ' ELSE ' . $this->table_left . ' END, ' . $this->table_right . ' = CASE WHEN ' . $this->table_right . ' > ' . $leftId . ' THEN ' . $this->table_right . ' - ' . $deltaId . ' ELSE ' . $this->table_right . ' END ' . 'WHERE ' . $this->table_right . ' > ' . $rightId;
         $sql .= $condition;
         $res = $this->db->query($sql);
         $this->db->commit();
         return TRUE;
     } catch (Exception $e) {
         $this->db->rollBack();
     }
 }
开发者ID:ei-grad,项目名称:phorm,代码行数:31,代码来源:Tree.php

示例14: beginTransaction

 /**
  * Démarre le mode transactionnel
  * 
  * @access public
  * @return boolean
  */
 function beginTransaction()
 {
     return $this->pdo->beginTransaction();
 }
开发者ID:bibwho,项目名称:MATPbootstrap,代码行数:10,代码来源:sqlite_pdo.php

示例15: putMenuAsHistory

/**
 * Procedimiento que almacena el item de menú como parte del historial de 
 * navegación del usuario indicado por $uid. El historial del usuario debe 
 * cumplir las siguientes propiedades:
 * - El historial es una lista con un máximo número de items (5), parecido, pero
 *   no idéntico, a una cola FIFO.
 * - Los items están ordenados por su ID de inserción. El item más reciente es
 *   el item de mayor número de inserción.
 * - Repetidas llamadas sucesivas a esta función con el mismo valor de $uid y 
 *   $menu deben dejar la lista inalterada, asumiendo que no hayan otras 
 *   ventanas de navegación abierta.
 * - Si la lista tiene su número máximo de items y se agrega un nuevo item que
 *   no estaba previamente presente en la lista, el item más antiguo se olvida.
 * - Si el item resulta idéntico en menú a uno que ya existe, debe de quitarse
 *   de su posición actual y colocarse en la parte superior de la lista. El 
 *   número de items debe quedar inalterado.
 * 
 * @param   object  $pdbACL     Objeto paloDB conectado a las tablas de ACL.
 * @param   object  $pACL       Objeto paloACL para consultar IDs de menú.
 * @param   integer $uid        ID de usuario para el historial
 * @param   string  $menu       Item de menú a insertar en el historial
 * 
 * @return  bool    VERDADERO si se inserta el item, FALSO en error.  
 */
function putMenuAsHistory($pdbACL, $pACL, $uid, $menu)
{
    global $arrConf;
    $pDB = new paloDB($arrConf['elastix_dsn']['settings']);
    if (empty($pDB->errMsg)) {
        $uelastix = get_key_settings($pDB, 'uelastix');
        if ((int) $uelastix != 0) {
            return TRUE;
        }
    }
    $id_resource = $pACL->getResourceId($menu);
    if (is_null($id_resource)) {
        return FALSE;
    }
    // Leer historial actual. El item 0 es el más reciente
    $sqlselect = <<<SQL_LEER_HISTORIAL
SELECT aus.id AS id, ar.id AS id_menu FROM acl_user_shortcut aus, acl_resource ar
WHERE id_user = ? AND type = 'history' AND ar.id = aus.id_resource
ORDER BY aus.id DESC    
SQL_LEER_HISTORIAL;
    $historial = $pdbACL->fetchTable($sqlselect, TRUE, array($uid));
    if (!is_array($historial)) {
        return FALSE;
    }
    if (count($historial) > 0 && $historial[0]['id_menu'] == $id_resource) {
        return TRUE;
    }
    // Idempotencia
    for ($i = 0; $i < count($historial); $i++) {
        $historial[$i]['modified'] = FALSE;
    }
    // Procesar la lista según las reglas requeridas
    $shiftindex = NULL;
    for ($i = 0; $i < count($historial); $i++) {
        if ($historial[$i]['id_menu'] == $id_resource) {
            $shiftindex = $i;
            break;
        }
    }
    if (is_null($shiftindex) && count($historial) >= 5) {
        $shiftindex = count($historial);
    }
    // Insertar nuevo item al inicio, corriendo los items si es necesario
    if (!is_null($shiftindex)) {
        for ($i = $shiftindex; $i > 0; $i--) {
            if ($i < count($historial)) {
                $historial[$i]['id_menu'] = $historial[$i - 1]['id_menu'];
                $historial[$i]['modified'] = TRUE;
            }
        }
        $historial[0]['id_menu'] = $id_resource;
        $historial[0]['modified'] = TRUE;
    } else {
        array_unshift($historial, array('id' => NULL, 'id_menu' => $id_resource, 'modified' => TRUE));
    }
    // Guardar en la DB todas las modificaciones
    $pdbACL->beginTransaction();
    foreach ($historial as $item) {
        if ($item['modified']) {
            if (is_null($item['id'])) {
                $sqlupdate = 'INSERT INTO acl_user_shortcut (id_resource, id_user, type) VALUES (?, ?, ?)';
                $paramsql = array($item['id_menu'], $uid, 'history');
            } else {
                $sqlupdate = 'UPDATE acl_user_shortcut SET id_resource = ? WHERE id_user = ? AND type = ? AND id = ?';
                $paramsql = array($item['id_menu'], $uid, 'history', $item['id']);
            }
            if (!$pdbACL->genQuery($sqlupdate, $paramsql)) {
                $pdbACL->rollBack();
                return FALSE;
            }
        }
    }
    $pdbACL->commit();
    return TRUE;
}
开发者ID:hardikk,项目名称:HNH,代码行数:99,代码来源:misc.lib.php


注:本文中的object::beginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。