I am trying to execute the following.
public function result_multi($sql) {
try {
mysqli_multi_query($this->db_connection,$sql);
$result=mysqli_store_result($this->db_connection);
$row=mysqli_fetch_row($result);
}
$b=new DB;
$sql="INSERT INTO payout (mid, type, datetime) VALUES ('0','BC',
NOW());SELECT LAST_INSERT_ID();";
$b->result_multi($sql);
$row returns NULL and $result return FALSE, however when I execute the SQL query in phpmyadmin it works.
2
Answers
When it comes to fetching the results of a multi query, the
mysqli_multi_query
documentation states :So you would need to call
mysqli_next_result
once to access the results of the second query, and thenmysqli_store_result/mysqli_fetch_row
to fetch the id.But in your use case, it seems like a simpler way to proceed is to use
mysqli_insert_id
method, like :PS : you should also check for errors after opening the connection to the database.
I need more code for this, because you used the multi sql so must have more query.
Try this code if only one query sql :