Tuesday 20 February 2018

PHP Mysql Create Table

Create table:
Create table statement is used to create a table in MySQL
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

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...