我使用以下查询创建临时表,但该表未显示在数据库中,也不会在执行查询时出现任何错误。
$sql2 = "CREATE TEMPORARY TABLE `temp_result` (
`tscore` int(20) NOT NULL,
`name` varchar(100) NOT NULL,
`validsc` int(20) NOT NULL,
`des` varchar(100) NOT NULL
)";
mysql_query($sql2);
创建临时表后,我将向其中插入一些数据。
$sql3 = "INSERT INTO temp_result (tscore, name,validsc, des) VALUES ('$L', 'L-Scale','1', '$desl'),('$F', 'F-Scale','1', '$desf'),('$K', 'K-Scale', '1', '$desk'),('$HS', 'Hypochondria','0', '$deshs'),('$D', 'Depression', '0', '$desd'),('$HY', 'Hysteria', '0', '$deshy'),('$PD', 'Psychopathic-Deviation', '0', '$despd'),('$MFM', 'Masculinity-Femininity','0', '$desmfm'),('$PA', 'Paranoia','0', '$despa'),('$PT', 'Psychoastenia','0', '$despt'),('$SC', 'Schizophrenia','0', '$dessc'),('$MA', 'Hypomania','0', '$desma'),('$SI', 'Introversion Social','0', '$dessi') ";
mysql_query($sql3);
但我不确定为什么桌子没有创建。
答案 0 :(得分:1)
临时表不是在数据库中创建的,它们是会话并存储在内存中直到会话结束。
答案 1 :(得分:1)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "DBNAME";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$sql = "CREATE TEMPORARY TABLE fbsign (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
fname VARCHAR(30) NOT NULL,
sname VARCHAR(30) NOT NULL,
mob VARCHAR(50),
pass VARCHAR(30) NOT NULL,
)";
if ($conn->query($sql) === TRUE)
{
$ins="insert into fbsign (fname,sname,mob,pass)values('$fname','$sname','$mob','$pass')";
$ex=$conn->query($ins);
if($ex)
{
echo "Inserted successfully::";
}
else
{
echo "ERROR::";
}
}
else
{
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>