ID: 32195 Updated by: [EMAIL PROTECTED] Reported By: toma at smartsemantics dot com -Status: Feedback +Status: Bogus Bug Type: MySQLi related Operating System: Linux RedHat Enterprise 3 PHP Version: 5.0.3 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php See http://bugs.mysql.com/?id=8988 Previous Comments: ------------------------------------------------------------------------ [2005-03-06 16:14:35] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-03-05 00:34:18] toma at smartsemantics dot com I reversed my expected and actual results... what I am looking to get is insert ids with a value of zero. Please reverse them. ------------------------------------------------------------------------ [2005-03-05 00:26:30] toma at smartsemantics dot com Description: ------------ I am executing a loop of 4 statements: 2 INSERTS returning insert IDs and 2 SELECTS. The last 2 SELECTS both show insert IDs equal to the value of the last successful INSERT. I believe the appropriate behavior should be that mysqli_insert_id return a value of zero or null for the SELECTs. Reproduce code: --------------- <?php $server='localhost'; $user='parkdomains'; $pass='[EMAIL PROTECTED]@ce$'; $database='ParkDomains'; ###CONNECT TO DATABASE $dbconn=mysqli_init(); mysqli_options($dbconn,MYSQLI_OPT_CONNECT_TIMEOUT,8); //mysqli_real_connect($dbconn,$server,$user,$pass,$database,null,null,MYSQLI_CLIENT_FOUND_ROWS); mysqli_real_connect($dbconn,$server,$user,$pass,$database,null,null,MYSQLI_CLIENT_FOUND_ROWS); if(mysqli_connect_errno()){ printf("Can't connect to the MySQL Server (".$server."): %s\n", mysqli_connect_error()); } @mysqli_select_db($dbconn,$database); if(mysqli_error($dbconn)) $ReportError(sprintf("Can't select the MYSQL database (".$database."): %s\n", mysqli_error($dbconn)),1); ###OUR SQL STATEMENTS### $sql_statements_statements=array(); $sql_statements[]="INSERT INTO test () VALUES('','test')"; $sql_statements[]="INSERT INTO test () VALUES('','test')"; $sql_statements[]="SELECT * FROM test LIMIT 3"; $sql_statements[]="SELECT * FROM test LIMIT 2"; ###COMBINE THEM INTO ONE### $query=implode(';',$sql_statements); echo $query."<BR>\n"; $ret=array(); reset($sql_statements); if(mysqli_multi_query($dbconn,$query)){ do{ $obj=new stdClass(); list(,$obj->sql)=each($sql_statements); $res=mysqli_store_result($dbconn); $obj->affected_rows=mysqli_affected_rows($dbconn); $obj->last_insert_id=mysqli_insert_id($dbconn); if($res){ if(mysqli_num_rows($res)>0){ while ($row=mysqli_fetch_row($res)){ $obj->result[]=$row; }; mysqli_free_result($res); } } $ret[]=$obj; }while(mysqli_next_result($dbconn)); } echo "<pre>"; print_r($ret); ?> Expected result: ---------------- INSERT INTO test () VALUES('','test');INSERT INTO test () VALUES('','test');SELECT * FROM test LIMIT 3;SELECT * FROM test LIMIT 2 Array ( [0] => stdClass Object ( [sql] => INSERT INTO test () VALUES('','test') [affected_rows] => 1 [last_insert_id] => 46 ) [1] => stdClass Object ( [sql] => INSERT INTO test () VALUES('','test') [affected_rows] => 1 [last_insert_id] => 47 ) [2] => stdClass Object ( [sql] => SELECT * FROM test LIMIT 3 [affected_rows] => 3 [last_insert_id] => 47 [result] => Array ( [0] => Array ( [0] => 30 [1] => 0 ) [1] => Array ( [0] => 31 [1] => 0 ) [2] => Array ( [0] => 32 [1] => 0 ) ) ) [3] => stdClass Object ( [sql] => SELECT * FROM test LIMIT 2 [affected_rows] => 2 [last_insert_id] => 47 [result] => Array ( [0] => Array ( [0] => 30 [1] => 0 ) [1] => Array ( [0] => 31 [1] => 0 ) ) ) ) Actual result: -------------- INSERT INTO test () VALUES('','test');INSERT INTO test () VALUES('','test');SELECT * FROM test LIMIT 3;SELECT * FROM test LIMIT 2 Array ( [0] => stdClass Object ( [sql] => INSERT INTO test () VALUES('','test') [affected_rows] => 1 [last_insert_id] => 46 ) [1] => stdClass Object ( [sql] => INSERT INTO test () VALUES('','test') [affected_rows] => 1 [last_insert_id] => 47 ) [2] => stdClass Object ( [sql] => SELECT * FROM test LIMIT 3 [affected_rows] => 3 [last_insert_id] => 0 [result] => Array ( [0] => Array ( [0] => 30 [1] => 0 ) [1] => Array ( [0] => 31 [1] => 0 ) [2] => Array ( [0] => 32 [1] => 0 ) ) ) [3] => stdClass Object ( [sql] => SELECT * FROM test LIMIT 2 [affected_rows] => 2 [last_insert_id] => 0 [result] => Array ( [0] => Array ( [0] => 30 [1] => 0 ) [1] => Array ( [0] => 31 [1] => 0 ) ) ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32195&edit=1