doucitan2544 2018-07-25 03:41
浏览 70

完全执行多个查询后如何执行单个查询?

Is it possible to execute a single query once the multi-query is fully executed in PHP/MYSQL? Actually, I want to insert a record in a table once the multi-query is fully executed.

 public function create_tables($data)
{

      $email = $data['email'];
      $name = $data['name'];
      $storepassword = $data['storepassword'];
      $created_date = date('Y/m/d H:i:s');

    // Connect to the database
    $mysqli = new mysqli($data['hostname'], $data['username'], $data['password'], $data['database']);

    // Check for errors
    if (mysqli_connect_errno()) {
        return false;
    }

    // Open the default SQL file
    $query = file_get_contents('assets/install.sql');

    // Execute a multi query
   $mysqli->multi_query($query);

   $insert = "INSERT INTO `users` (`fullname`, `email`, `password`, `role_id`, `outlet_id`, `created_user_id`, `created_datetime`, `updated_user_id`, `updated_datetime`, `status`) VALUES
    ('$name', '$email', '$storepassword', 1, 0, 1, '$created_date', 1, '$created_date', 1)";

$mysqli->query($insert);

    // Close the connection
    $mysqli->close();

    return true;
}
  • 写回答

1条回答 默认 最新

  • doujie7886 2018-07-25 11:02
    关注

    add this after the mutli_query

    while (mysqli->next_result()){
      //do nothing
    }
    

    this will cause the execution to loop through the multi_query results thus forcing the script to wait until the multi_query is fully processed before moving on to the next part of the script.

    another approach would be to include the final query at the end of and as part of the multi_query

    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来