anantamu.com


PHP MySQL Create Table


Table is a collection data stored in a table. It consists of columns and rows.

ID is primary key, which contains unique value and auto increment value.


CREATE TABLE

CREATE TABLE TABLE_NAME ( ID INT(5) UNSIGNED NOTNULL PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(50) NOTNULL, DOB DATE NOTNULL )


CREATE TABLE in Database

<?php
$servername = "localhost";
$username1 = "root";
$password1 = "";
$dbname = "sample";
//server connection
$connection = mysqli_connect($servername, $username1, $password1, $dbname);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}

$sqlQuery = "CREATE TABLE profile
(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Name varchar(50),
Address varchar(500)
)";
// query is excute here
if (mysqli_query($connection, $sqlQuery)) {
  echo "Table MyGuests created successfully";
} else {
  echo "Error creating table: " . mysqli_error($connection);
}
mysqli_close($connection);
?>