Create
table:
if(mysqli_query($con, $sql)){
Create table statement is used to create a table in MySQL
Syntax:
Syntax:
Create table table name( fieldname1
datatype(),fieldname2 datatype()...);
Example:
create table emp(id int(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY ,name
varchar(30) NOT NULL,salary decimal(7,2) NOT NULL);
Example:
<?php
$servername=
'localhost’;
$username = 'root';
$password = '';
$dbname='lp'
$con =
mysqli_connect($servername, $username, $password,$dbname);
if(! $con )
{
die('Could not connect: ' . mysqli_error());
}
echo 'Connected
successfully';
$sql = "create
table emp(id int(10)UNSIGNED AUTO_INCREMENT PRIMARY KEY ,name varchar(30) NOT NULL,salary decimal(7,2) NOT
NULL)";
if(mysqli_query($con, $sql)){
echo "Table created successfully";
}
else{
echo "Could
not create table: ". mysqli_error($con);
}
mysqli_close($con);
?>
Output:
Connected
successfully
Table created successfully
No comments:
Post a Comment