Jump to content

MySQLi result ID with multi_query


j9sjam3

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.