[ 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/mysql/ -> MySQLIdGenerator.php (source)

   1  <?php
   2  
   3  require_once 'creole/IdGenerator.php';
   4  
   5  /**
   6   * MySQL IdGenerator implimenation.
   7   *
   8   * @author    Hans Lellelid <hans@xmpl.org>
   9   * @version   $Revision: 1.6 $
  10   * @package   creole.drivers.mysql
  11   */
  12  class MySQLIdGenerator implements IdGenerator {
  13      
  14      /** Connection object that instantiated this class */
  15      private $conn;
  16  
  17      /**
  18       * Creates a new IdGenerator class, saves passed connection for use
  19       * later by getId() method.
  20       * @param Connection $conn
  21       */
  22      public function __construct(Connection $conn)
  23      {
  24          $this->conn = $conn;
  25      }
  26      
  27      /**
  28       * @see IdGenerator::isBeforeInsert()
  29       */
  30      public function isBeforeInsert()
  31      {
  32          return false;
  33      }    
  34      
  35      /**
  36       * @see IdGenerator::isAfterInsert()
  37       */
  38      public function isAfterInsert()
  39      {
  40          return true;
  41      }
  42          
  43      /**
  44       * @see IdGenerator::getIdMethod()
  45       */
  46      public function getIdMethod()
  47      {
  48          return self::AUTOINCREMENT;
  49      }
  50      
  51      /**
  52       * Returns last-generated auto-increment ID.
  53       * 
  54       * Note that for very large values (2,147,483,648 to 9,223,372,036,854,775,807) a string
  55       * will be returned, because these numbers are larger than supported by PHP's native
  56       * numeric datatypes.
  57       * 
  58       * @see IdGenerator::getId()
  59       */
  60      public function getId($unused = null)
  61      {
  62          $insert_id = mysql_insert_id($this->conn->getResource());
  63          if ( $insert_id < 0 ) {
  64              $insert_id = null;
  65              $result = mysql_query('SELECT LAST_INSERT_ID()', $this->conn->getResource());
  66              if ( $result ) {
  67                  $row = mysql_fetch_row($result);
  68                  $insert_id = $row ? $row[0] : null;
  69              }
  70          }
  71          return $insert_id;
  72      }
  73      
  74  }
  75  


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