00001 <?php 00002 00003 require_once 'creole/IdGenerator.php'; 00004 00012 class MySQLIdGenerator implements IdGenerator { 00013 00015 private $conn; 00016 00022 public function __construct(Connection $conn) 00023 { 00024 $this->conn = $conn; 00025 } 00026 00030 public function isBeforeInsert() 00031 { 00032 return false; 00033 } 00034 00038 public function isAfterInsert() 00039 { 00040 return true; 00041 } 00042 00046 public function getIdMethod() 00047 { 00048 return self::AUTOINCREMENT; 00049 } 00050 00060 public function getId($unused = null) 00061 { 00062 $insert_id = mysql_insert_id($this->conn->getResource()); 00063 if ( $insert_id < 0 ) { 00064 $insert_id = null; 00065 $result = mysql_query('SELECT LAST_INSERT_ID()', $this->conn->getResource()); 00066 if ( $result ) { 00067 $row = mysql_fetch_row($result); 00068 $insert_id = $row ? $row[0] : null; 00069 } 00070 } 00071 return $insert_id; 00072 } 00073 00074 } 00075