While looking for a way to temporarily save the search results when a user searches for a hotel free between particular dates i came across temporary tables.

在用户在特定日期之间免费搜索酒店时寻找暂时保存搜索结果的方法时,我遇到了临时表。

But certain questions are not answered even in mysql manual.... like...

但是即使在mysql手册中也没有回答某些问题......就像......

  1. Will the temporary table be unique for each user that executes the script...? Or will it be overwritten when two different users run the script at the same time...?

    临时表对于执行脚本的每个用户都是唯一的吗?或者当两个不同的用户同时运行脚本时它会被覆盖......?

  2. When will the table be destroyed..? When the user closes the browser window or just navigates away from the page in which the script runs...?

    桌子何时会被销毁..?当用户关闭浏览器窗口或只是导航脚本运行的页面时......?

Thanks for your clarifications...

谢谢你的澄清......

This is how i do it....

这是我怎么做的....

$table = "CREATE OR REPLACE TEMPORARY TABLE $free_room(
              room_id INT(5),
              room_name VARCHAR(150),
              max_persons INT(1),
              rooms_free INT(1),
              room_price INT(6),
              hotel_id INT(4),
              hotel_name VARCHAR(100),
              hotel_stars INT(1),
              hotel_type INT(1)) ENGINE=MEMORY";

    $query_getFreeRooms = "INSERT INTO  $free_room
                           SELECT $rooms.room_id,
                                  $rooms.room_name,
                                  $rooms.max_persons,
                                  $rooms.total_rooms - $rooms.booked_rooms AS rooms_free,
                                  $rooms.room_price,
                                  $hotels.hotel_id,
                                  $hotels.hotel_name,
                                  $hotels.hotel_stars,
                                  $hotels.hotel_type
                           FROM   $hotels,$rooms
                           WHERE  $rooms.room_id NOT IN (SELECT room_id
                                                         FROM   $reservations
                                                         WHERE  $dateCheck)
                           AND    $hotels.hotel_city = '$city_search1'
                           AND    $hotels.hotel_id = $rooms.hotel_id
                           AND    $hotels.hotel_deleted = '0'
                           AND    $rooms.room_deleted = '0'";

1 个解决方案

#1


29

Quoting the MySQL manual page of CREATE TABLE :

引用CREATE TABLE的MySQL手册页:

You can use the TEMPORARY keyword when creating a table.
A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed.
This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name.

您可以在创建表时使用TEMPORARY关键字。 TEMPORARY表仅对当前连接可见,并在关闭连接时自动删除。这意味着两个不同的连接可以使用相同的临时表名,而不会相互冲突或与现有的同名非TEMPORARY表冲突。

Considering that two users will have two distinct connections, the table will be unique for each user.

考虑到两个用户将具有两个不同的连接,该表对于每个用户将是唯一的。

The temporary table will be dropped when the connection that created it is closed -- in PHP, at least, it means when the script that generates the page ends (So, generally, even before the users actually reads the page)

当创建它的连接关闭时,临时表将被删除 - 在PHP中,至少,这意味着生成页面的脚本结束时(通常,甚至在用户实际读取页面之前)

更多相关文章

  1. mysql启动脚本——指定数据目录并指定配置文件
  2. MVC框架——学生信息管理系统(多表,多事务如何处理,一个用户如何共
  3. MySQL5.7以上版本root用户空密码修改(windows系统、zip版MySQL)
  4. Spring Security ACL使用MySQL配置与数据库脚本
  5. MySql查询脚本,每月统计活动用户。
  6. MySQL导出和导入SQL脚本
  7. MySQL用户管理(5.7.20-winx64)
  8. Laravel - 如何为用户赋予多重角色?
  9. Linux下修改MySQL用户(root)密码

随机推荐

  1. Android技术内幕
  2. Android热修复(2):AndFix热修复框架的使用
  3. android仿网易云音乐、即时通讯、bilibil
  4. [转]android:layout_gravity 和 android:
  5. Android(安卓)-- StateMachine瑙f瀽
  6. Android 多线程之几个基本问题
  7. Android通知栏微技巧,8.0系统中通知栏的适
  8. Andriod应用开发--第二章作业1--习题答案
  9. Android(安卓)由android:process引发LMK
  10. 请收好这一份全面 & 详细的Android学习指