[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/creole/drivers/mysqli/ -> MySQLiIdGenerator.php (source)

   1  <?php
   2  /*
   3   * $Id: MySQLiIdGenerator.php,v 1.4 2004/09/18 09:15:49 sb Exp $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://creole.phpdb.org>.
  20   */
  21  
  22  require_once 'creole/IdGenerator.php';
  23  
  24  /**
  25   * MySQLi implementation of IdGenerator.
  26   *
  27   * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  28   * @version   $Revision: 1.4 $
  29   * @package   creole.drivers.mysqli
  30   */
  31  class MySQLiIdGenerator implements IdGenerator {
  32      /** Connection object that instantiated this class */
  33      private $conn;
  34  
  35      /**
  36       * Creates a new IdGenerator class, saves passed connection for use
  37       * later by getId() method.
  38       * @param Connection $conn
  39       */
  40      public function __construct(Connection $conn)
  41      {
  42          $this->conn = $conn;
  43      }
  44  
  45      /**
  46       * @see IdGenerator::isBeforeInsert()
  47       */
  48      public function isBeforeInsert()
  49      {
  50          return false;
  51      }
  52  
  53      /**
  54       * @see IdGenerator::isAfterInsert()
  55       */
  56      public function isAfterInsert()
  57      {
  58          return true;
  59      }
  60  
  61      /**
  62       * @see IdGenerator::getIdMethod()
  63       */
  64      public function getIdMethod()
  65      {
  66          return self::AUTOINCREMENT;
  67      }
  68  
  69      /**
  70       * Returns last-generated auto-increment ID.
  71       *
  72       * Note that for very large values (2,147,483,648 to 9,223,372,036,854,775,807) a string
  73       * will be returned, because these numbers are larger than supported by PHP's native
  74       * numeric datatypes.
  75       *
  76       * @see IdGenerator::getId()
  77       */
  78      public function getId($unused = null)
  79      {
  80          $resource = $this->conn->getResource();
  81          $insert_id = mysqli_insert_id($resource);
  82  
  83          if ( $insert_id < 0 ) {
  84              $insert_id = null;
  85  
  86              $result = mysqli_query($resource, 'SELECT LAST_INSERT_ID()');
  87  
  88              if ( $result ) {
  89                  $row = mysqli_fetch_row($result);
  90                  $insert_id = $row ? $row[0] : null;
  91              }
  92          }
  93  
  94          return $insert_id;
  95      }
  96  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7