Reputation: 47
I use the following query to create temporary table but the table does not show up in the database nor give any error while executing the query.
$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);
After creating tempory table i am going to insert some data into it.
$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);
But I am not sure why table is not creating.
Upvotes: 0
Views: 1339
Reputation: 268
<?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();
?>
Upvotes: 0
Reputation: 691
temporary tables aren't created in the database, they are by session and stored in memory until the session is ended.
Upvotes: 3