我正在尝试在PHP上创建一个表,但它不会创建任何表
$Usernaam = YuYu;
$UserAppartement = $Usernaam . "_Appartement";
$Usertable = $Usernaam. "_Huizen";
$immodata = mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("immodata", $immodata);
$sql = "create table $UserAppartement
(
ID int NOT NULL AUTO_INCREMENT ,
SoortLokatie_ID int(11) NOT NULL,
Verdieping varchar(15) NOT NULL,
GasMN int(15) ,
ElektriciteitMN int(15) ,
WaterMN int(15) ,
EAN_Gas varchar(15) ,
EAN_Elektriciteit varchar(15) ,
Oppervlakte int(3) ,
Kamers int(1),
Tuin TINYINT(1) ,
Terras TINYINT(1) ,
Living TINYINT(1),
Keuken TINYINT(1) ,
Balkon TINYINT(1) ,
Badkamer TINYINT(1) ,
Toilet TINYINT(1),
Beschrijving varchar(1000) default 'Geen beschrijving',
Status_ID int(1),
Zoek_ID varchar(6),
Huis_ID int(11),
PRIMARY KEY (ID),
FOREIGN KEY (Huis_ID) REFERENCES $Usertable(ID);
)
";
echo "Table has been created ";
mysql_query($sql, $immodata);
最后的回声有效,但是没有创建表。我没有收到任何错误消息。
答案 0 :(得分:0)
您可以使用此代码解决问题
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Create table
$sql="CREATE TABLE Persons(FirstName CHAR(30),LastName CHAR(30),Age INT)";
// Execute query
if (mysqli_query($con,$sql))
{
echo "Table persons created successfully";
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
?>