我正在尝试使用 PHP 和 MySQL 创建一个表。第一个表不会在数据库上创建,但第二个会。我认为这是我的参数/约束。这是我的代码:
if ($conn==true){
$tablefriends = "CREATE TABLE IF NOT EXISTS friends (
friend_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
friend_email VARCHAR(64) NOT NULL PRIMARY KEY ,
password VARCHAR(16) NOT NULL ,
profile_name VARCHAR(32) NOT NULL ,
date_started DATE NOT NULL ,
num_of_friends INT UNSIGNED ZEROFILL NULL default '0'
);";
$tablemyfriends = "CREATE TABLE IF NOT EXISTS myfirends (
friend_id1 INT NOT NULL ,
friend_id2 INT NOT NULL
);";
$resulttf = @mysqli_query($conn, $tablefriends);
if($resulttf==false){
echo "<p>Failed to create friends table</p>";
}
$resulttmf = @mysqli_query($conn, $tablemyfriends);
if($resulttmf==false){
echo "<p>Failed to create myfriends table</p>";
}else{
echo"<p>Tables successfully created</p>";
}
mysqli_close($conn);
}
else {
echo "<p>Failed to connect</p>";
}
不知道为什么导师说要分两次入小学