j9sjam3 Posted April 1, 2011 Share Posted April 1, 2011 Hello again. I have built a multi-insert MySQLi function. The problem is, I cannot retreive the ID from each query. If you could help, that would be brilliant. <?php public function Query($sql) { $this->IsConnected(); $this->timeStart = microtime(true); $this->queries = $sql; // $sql is below $this->StartTransaction(); $this->lastResult = mysqli_multi_query($this->link, $sql); if($result = mysqli_store_result($this->link)) { $this->lastID .= mysqli_insert_id($this->link); mysqli_free_result($result); } while(mysqli_next_result($this->link)); if(!$this->lastResult) { $this->RollbackTransaction(); $this->Error(null, 0, __LINE__); } $this->EndTransaction(); if(strpos(strtolower($sql), "insert") === 0) { echo $this->lastID; if(!$this->lastID) { $this->Error("", 0, __LINE__); } else { return $this->lastResult; $this->queryQueue = ""; } } elseif(strpos(strtolower($sql), "select") === 0) { $this->LastID = 0; } $this->timeEnd = microtime(true); $this->timeTotal = ($this->timeEnd - $this->timeStart); $removeE = explode('E', $this->timeTotal); $this->timeTotal = $removeE[0]; $sql var <?php $sql = "INSERT INTO users (username, password) VALUES ('1', 'Jsa');INSERT INTO users (username, password) VALUES ('2', 'Jsa');INSERT INTO users (username, password) VALUES ('2', 'Jsa');INSERT INTO users (username, password) VALUES ('2', 'Jsa');"; Thanks. Link to comment https://forums.phpfreaks.com/topic/232386-mysqli-result-id-with-multi_query/ Share on other sites More sharing options...
j9sjam3 Posted April 1, 2011 Author Share Posted April 1, 2011 Can anyone help? Would be much appreciated... Link to comment https://forums.phpfreaks.com/topic/232386-mysqli-result-id-with-multi_query/#findComment-1195509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.