Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m stuck on trying to get my database to produce these tables using the php co

ID: 3756572 • Letter: I

Question

I'm stuck on trying to get my database to produce these tables using the php code. Im using uwamp and mysql to create this.

Code

<?php
$servername = "localhost:8888";
$username= "root";
$password = "root";
$dbname = "myDB";

//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAl'IP
)";
if ($conn->query($sql) === TRUE) {
   echo "Table MyGuests created successfully";
} else {
   echo "Error creating table: " . $conn->error;
}
$conn->close();
?>

MySQL Connections O cis495 myDB root localhost:8888 root localhost:8888

Explanation / Answer

If you have any doubts, please give me comment...

<?php
$servername = "localhost:8888";
$username= "root";
$password = "root";
$dbname = "myDB";

//Create connection
$conn = new mysqli($servername, $username, $password);
//Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}

$conn->query("CREATE DATABASE IF NOT EXISTS $dbname");

mysqli_select_db($conn, $dbname);

echo "Connected successfully";

// sql to create table

$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAl'IP
)";
if ($conn->query($sql) === TRUE) {
   echo "Table MyGuests created successfully";
} else {
   echo "Error creating table: " . $conn->error;
}
$conn->close();
?>