00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 require_once 'creole/IdGenerator.php';
00023
00031 class MySQLiIdGenerator implements IdGenerator {
00033 private $conn;
00034
00040 public function __construct(Connection $conn)
00041 {
00042 $this->conn = $conn;
00043 }
00044
00048 public function isBeforeInsert()
00049 {
00050 return false;
00051 }
00052
00056 public function isAfterInsert()
00057 {
00058 return true;
00059 }
00060
00064 public function getIdMethod()
00065 {
00066 return self::AUTOINCREMENT;
00067 }
00068
00078 public function getId($unused = null)
00079 {
00080 $resource = $this->conn->getResource();
00081 $insert_id = mysqli_insert_id($resource);
00082
00083 if ( $insert_id < 0 ) {
00084 $insert_id = null;
00085
00086 $result = mysqli_query($resource, 'SELECT LAST_INSERT_ID()');
00087
00088 if ( $result ) {
00089 $row = mysqli_fetch_row($result);
00090 $insert_id = $row ? $row[0] : null;
00091 }
00092 }
00093
00094 return $insert_id;
00095 }
00096 }