我从学校接到了这个任务,我对如何做到这一点感到困惑和迷茫。所以基本上我必须为数据库创建 2 个表,但我必须从 php 创建。
我创建了第一个表,但由于某种原因没有创建第二个。然后,我必须分别用 10 和 20 条样本记录填充第一个和第二个表,填充,这是否意味着添加更多的假用户?如果是这样,它像下面显示的代码吗?
*我在填充的第二部分也有错误
十分感谢你的帮助。
<?php
$host = "host";
$user = "me";
$pswd = "password";
$dbnm = "db";
$conn = @mysqli_connect($host, $user, $pswd, $dbnm);
if (!$conn)
die ("<p>Couldn't connect to the server!<p>");
$selectData = @mysqli_select_db ($conn, $dbnm);
if(!$selectData)
{
die ("<p>Database Not Selected</p>");
}
//1st table
$sql = "CREATE TABLE IF NOT EXISTS `friends`
(
`friend_id` INT NOT NULL auto_increment,
`friend_email` VARCHAR(20) NOT NULL,
`password` VARCHAR(20) NOT NULL,
`profile_name` VARCHAR(30) NOT NULL,
`date_started` DATE NOT NULL,
`num_of_friends` INT unsigned,
PRIMARY KEY (`friend_id`)
)";
//2nd table
$sqlMyfriends = "CREATE TABLE `myfriends`
(
`friend_id1` INT NOT NULL,
`friend_id2` INT NOT NULL,
)";
$query_result1 = @mysqli_query($conn, $sql);
$query_result2 = @mysqli_query($conn, $sqlMyfriends);
//populating 1st table
$sqlSt3="INSERT INTO friends (friend_id, friend_email, password, profile_name, date_started, num_of_friends)
VALUES('NULL','email@email.com','123','abc','2012-10-25', 5)";
$queryResult3 = @mysqli_query($dbConnect,$sqlSt3)
//populating 2nd table
$sqlSt13="INSERT INTO myfriends VALUES(1,2)";
$queryResult13=@mysqli_query($dbConnect,$sqlSt13);
mysqli_close($conn);
?>