Page 1 of 1

mysqli insert_id

Posted: Thu Mar 31, 2011 2:59 pm
by paynod
I'm trying to retrieve the mysqli insert_id from an INSERT database query but each time the result is 0. PLease can someone point me in the right direction as to what i'm doing wrong. Here is my query

Code: Select all

       $mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
	$this->execSQL("INSERT INTO itm_pic_detail(itm_pic_name, itm_pic_type, itm_pic_size) VALUES (?,?,?)", array('sss', $filename, $type, $size),true);
	$mysqli->insert_id;
	$message = "$filename uploaded successfully";
	}
	if ($this->_renamed) {
	$message .= " and renamed $name";
	}
	$this->_messages[] = $message;
	} else {
    $this->_messages[] = 'Could not upload ' . $filename;
	}
	  }
	}
[ /syntax]

Re: mysqli insert_id

Posted: Thu Mar 31, 2011 6:13 pm
by social_experiment
The Manual wrote:The mysqli_insert_id() function returns the ID generated by a query on a table with a column having the AUTO_INCREMENT attribute. If the last query wasn't an INSERT or UPDATE statement or if the modified table does not have a column with the AUTO_INCREMENT attribute, this function will return zero.
Do you have an auto-imcrementing column in your table?
P.S No " " are needed when using the PHP Code button.