我想使用之前创建的schema.sql文件在mysql中创建表,但是php创建第一个表并在下一个表中给我错误,尽管sql命令没有问题
<?php
$host = "localhost";
$username = "root";
$password = "pass";
$dbname = "test";
$content = file_get_contents("schema.sql");
$ms = new mysqli($host,$username,$password,$dbname);
if($ms->connect_error){
die("con failed : ".$ms->connect_error);
}
if($ms->query($content) === true){
echo "ok"."\n";
}else{
echo $ms->error . "\n";
}
create table users (
id int primary key auto_increment,
username varchar(255) not null unique ,
password varchar(255) not null ,
email varchar (255) not null unique ,
time_created datetime not null
);
create table todos (
id int primary key auto_increment,
user_id int not null,
title varchar (255) not null ,
content text ,
time_created datetime not null ,
constraint foreign key (user_id) references users(id)
);
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create table todos (
id int primary key auto_increment,
user_id int not null' at line 10