我正在使用Xammp服务器,我在下面编写了创建表的php代码,这给了我语法错误
<?php
$con=@mysqli_connect('localhost', 'root', '', 'shop');
create table customer(
cust_id int primary key,
name varchar(255) ,
Email varchar(255)
);
?>
错误
语法错误,第6行C:\ xampp \ htdocs \ shop.php中的意外T_STRING
答案 0 :(得分:1)
您应该将查询分配到变量中。
$sql = "create table customer(
cust_id int primary key,
name varchar(255) ,
Email varchar(255)
)";
答案 1 :(得分:1)
你需要将create table语法设置为变量,然后用它来执行 mysqli_query
<?php
$con=@mysqli_connect('localhost', 'root', '', 'shop');
$sql = "create table customer(
cust_id int primary key,
name varchar(255) ,
Email varchar(255)
);";
if(mysqli_query($con, $sql)){
echo "Table created successfully";
} else {
echo "Table is not created successfully ";
}
?>
本教程https://www.tutorialspoint.com/mysqli/mysqli_create_tables.htm