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.

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

解决方案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.

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值