Mysql databases store data in tables.
For storage of data in the database is necessary that it contains at least one created MySql table.


Create table

To create table in MySql database used PHP function mysql_query().
The table creation command requires: name of the table, names of fields and definitions for each field.
SQL query using CREATE TABLE statement, after that we will execute this SQL query through passing it to the mysqli_query() function to finally create our tableis used to create a table in MySQL.


<?php
$dbhost 
"localhost";
$dbuser "yourusername";
$dbpass  "yourpassword";
$dbname "yourdatabase";
$conn mysqli_connect($dbhost$dbuser$dbpass $dbname);
if (!
$conn) {
    die(
"Connection failed: " mysqli_connect_error());
}
$sql "CREATE TABLE members (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)"
;
if (
mysqli_query($conn$sql)) {
    echo 
"Table members created successfully";
} else {
    echo 
"Error creating table: " mysqli_error($conn);
}
mysqli_close($conn);
?>

Show lists tables on MySql database

SQL SHOW TABLES FROM $dbname
This function retrieves a list of table names from a MySQL database.


<?php
$dbhost 
"localhost";
$dbuser "yourusername";
$dbpass "yourpassword";
$dbname "yourdatabase";
$conn mysql_connect($dbhost$dbuser$dbpass) or die    ("Error connecting to mysql");
mysql_select_db($dbname);

$sql "SHOW TABLES FROM $dbname";
$result mysql_query($sql);
if (!
$result) {
    echo 
"DB Error, could not list tables\n";
    echo 
"MySQL Error: " mysql_error();
    exit;
}
while (
$row mysql_fetch_row($result)) {
    echo 
"{$row[0]}<br>";
}
mysql_free_result($result);
?>

Delete (drop) MySql table

The drop table command is used to delete a table and all rows in the table.
Warning: Dropping the table is potentially a very bad thing to do. Any data stored in the table will be destroyed.




<?php
$dbhost 
"localhost";
$dbuser "yourusername";
$dbpass "yourpassword";
$dbname "yourdatabase";
$conn mysqli_connect($dbhost$dbuser$dbpass $dbname);
if (!
$conn) {
    die(
"Connection failed: " mysql_connect_error());
}
$sql "DROP TABLE members";
if (
mysqli_query($conn$sql)) {
    echo 
"Table members deleted successfully";
} else {
   die(
"Could not delete table: " mysql_error());
}
mysqli_close($conn);
?>

PHP Tutorial - MySQL Creating A Table (YouTube)