I'm using PHP to create a dynamic table in my database and store some data in it.
我正在使用PHP在我的数据库中创建一个动态表并在其中存储一些数据。
Sometimes when i run the query the table is created and data query is executed but then again if i refresh the query or refresh my page, it shows Error saying table doesn't exist and again if i refresh my page it will load data in 2 or 3 tries.
有时,当我运行查询时,表创建并执行数据查询,但如果我刷新查询或刷新页面,它会显示错误表示表不存在,如果我刷新页面,它将再次加载数据或3次尝试。
I'm creating table dynamically and then perform operation on it and at the end I'm dropping the table. Here is my code
我正在动态创建表,然后对它执行操作,最后我正在删除表。这是我的代码
<?php
$droptable = "DROP TABLE IF EXISTS temp_post";
if(!mysql_query($droptable))
{echo msql_error();}
$sqlcreatetable = "CREATE TABLE temp_post(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
seq_id INT (6),
name VARCHAR(64) NOT NULL)";
if(!mysql_query($sqlcreatetable))
{
echo " ERROR CREATING TABLE --> ".mysql_error();
}
else{
//query here
}
$sqldel = "DROP TABLE temp_post";
if(!mysql_query($sqldel)){
echo "ERROR DELETING TABLE --> ".mysql_error();
}
?>
I've gone through some other posts and tried the solutions but still its not working properly.Help!!.. CHEERS
我已经浏览了一些其他帖子并尝试了解决方案,但仍然无法正常工作。帮助!! .. CHEERS
2 个解决方案
#1
1
May be conflicts.. 2 simultaneous requests, so one request can drop table that is used by another request
Try to change CREATE TABLE
to CREATE TEMPORARY TABLE
可能是冲突.. 2个并发请求,因此一个请求可以删除另一个请求使用的表尝试将CREATE TABLE更改为CREATE TEMPORARY TABLE
#2
1
Why create and drop anyway? Use CREATE TEMPORARY TABLE
or just TRUNCATE
the table after use
为什么要创造和放弃呢?使用CREATE TEMPORARY TABLE或仅在使用后对表进行TRUNCATE
#1
1
May be conflicts.. 2 simultaneous requests, so one request can drop table that is used by another request
Try to change CREATE TABLE
to CREATE TEMPORARY TABLE
可能是冲突.. 2个并发请求,因此一个请求可以删除另一个请求使用的表尝试将CREATE TABLE更改为CREATE TEMPORARY TABLE
#2
1
Why create and drop anyway? Use CREATE TEMPORARY TABLE
or just TRUNCATE
the table after use
为什么要创造和放弃呢?使用CREATE TEMPORARY TABLE或仅在使用后对表进行TRUNCATE