n w

   

Geen Producten -




Gio`s Corner
Spices Blends  & exotic foods


		




       



The example is lack of insert_id in multi_query. Here is my example:
Assuming you have a new test_db in mysql like this:

create database if not exists test_db;
use test_db;
create table user_info (_id serial, name varchar(100) not null);
create table house_info (_id serial, address varchar(100) not null);

Then you run a php file like this:

define('SERVER', '127.0.01');
define('MYSQL_USER', 'your_user_name');
define('MYSQL_PASSWORD', 'your_password');

$db = new mysqli(SERVER, MYSQL_USER, MYSQL_PASSWORD, "test_db", 3306);
if ($db->connect_errno)
  echo "create db failed, error is ", $db->connect_error;
else {
  $sql = "insert into user_info "
    . "(name) values "
    . "('owen'), ('john'), ('lily')";
  if (!$result = $db->query($sql))
    echo "insert failed, error: ", $db->error;
  else
    echo "last insert id in query is ", $db->insert_id, " ";
  $sql = "insert into user_info"
    . "(name) values "
    . "('jim');";
  $sql .= "insert into house_info "
    . "(address) values "
    . "('shenyang')";
  if (!$db->multi_query($sql))
    echo "insert failed in multi_query, error: ", $db->error;
  else {
    echo "last insert id in first multi_query is ", $db->insert_id, " ";
    if ($db->more_results() && $db->next_result())
      echo "last insert id in second multi_query is ", $db->insert_id, " ";
    else
      echo "insert failed in multi_query, second query error is ", $db->error;
  }
  $db->close();
}
?>

You will get output like this:

last insert id in query is 1
last insert id in first multi_query is 4
last insert id in second multi_query is 1

Conclusion:
1 insert_id works in multi_query
2 insert_id is the first id mysql has used if you have insert multi values


Verzendkosten
 
Griekenland     Zwitserland     Malta     San Marino    
tot 2 kg 19.80 tot 5 kg 26.50 tot 10 kg 32.50 tot 20 kg 42.50

 
Denemarken     Slowakije     Tsjechie    
tot 2 kg 9.95 tot 20 kg 16.95

 
Nederland    
tot 30 kg 4.95

 
Spanje    
tot 30 kg 16.95

 
Luxemburg    
tot 30 kg 13.95

 
Duitsland    
tot 30 kg 9.95

 
Italie    
tot 30 kg 16.95

 
Verenigd Koninkrijk (UK)    
tot 30 kg 14.95

 
Oostenrijk    
tot 30 kg 15.95

 
Frankrijk    
tot 30 kg 14.95

 
Belgie    
tot 30 kg 9.95

  Copyright gio`s Corner 2020