一个mysql临时表对于每个访问创建它的脚本的用户来说都是唯一的

一个mysql临时表对于每个访问创建它的脚本的用户来说都是唯一的

本文介绍了一个mysql临时表对于每个访问创建它的脚本的用户来说都是唯一的...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在特定日期之间免费搜索酒店时,我正在寻找一种临时保存搜索结果的方法.

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.

但是某些问题甚至在mysql手册中也无法回答....就像...

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

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

  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...?

该表何时被销毁..?当用户关闭浏览器窗口或只是离开运行脚本的页面时...?

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...?

感谢您的澄清...

这就是我的方法....

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'";

推荐答案

引用MySQL CREATE TABLE 的手册页:

Quoting the MySQL manual page of CREATE TABLE :

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

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

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

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)

这篇关于一个mysql临时表对于每个访问创建它的脚本的用户来说都是唯一的...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:27