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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.