Create Table in MySQL Database Using PHP

Object-Oriented

<?php
$servername = "localhost";
$username = "root"; // when you work in your computer then use username name "root"
$password = ""; // when you work in your computer then use password Empty
$dbname = "myDataBase";
// In this Line Create connection Object-oriented
$conn = new mysqli($servername, $username, $password);
// In this Line  Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
// In this line create table
$sql = "CREATE TABLE tbl_student_record (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
name VARCHAR(30) NOT NULL,
class VARCHAR(30) NOT NULL,
subject VARCHAR(50)
)";

if ($conn->query($sql) === TRUE) {
    echo "tbl_student_record table has been created successfully";
} else {
    echo "tbl_student_record table has not been created successfully : " . $conn->error;
}
$conn->close();
?>

Procedural

<?php 
$servername = "localhost";
$username = "root"; // when you work in your computer then use username name "root"
$password = ""; // when you work in your computer then use password Empty
$dbname = "myDataBase";
// In this Line  Create connection Procedural
$conn = mysqli_connect($servername, $username, $password);
// In this Line  Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
//in this line create table
$sql = "CREATE TABLE tbl_student_record (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
name VARCHAR(30) NOT NULL,
class VARCHAR(30) NOT NULL,
subject VARCHAR(50)
)";
if (mysqli_query($conn, $sql) or die(mysqli_error($conn))) {
    echo "tbl_student_record table has been created successfully";
} else {
    echo "tbl_student_record table has not been created successfully ";
}
mysqli_close($conn);
?>