对于访问创建它的脚本的每个用户来说,mysql临时表是唯一的...?
当用户在特定日期之间搜索免费酒店时,在寻找一种临时保存搜索结果的方法时,我遇到了临时表。
但某些问题即使在 mysql 手册中也没有得到解答...比如...
临时表对于执行脚本的每个用户来说是唯一的吗...?或者当两个不同的用户同时运行脚本时它会被覆盖...?
表什么时候会被销毁..?当用户关闭浏览器窗口或只是离开脚本运行的页面时...?
感谢您的澄清...
这就是我的做法...
$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'";
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...
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...?
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'";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用 MySQL
CREATE TABLE
的手册页:考虑到两个用户将有两个不同的连接,该表对于每个用户来说都是唯一的。
当创建临时表的连接关闭时,临时表将被删除 - 至少在 PHP 中,这意味着生成页面的脚本结束时(因此,通常,甚至在用户实际读取页面之前)< /em>
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.
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)