Create Table Mysql PHP
Advertisements
Create Table Mysql PHP
Table is the collection of row and column, using below SQL query we can create own table in database.
Create Table in database
create table table_name ( id int(5) NOT NULL auto_increment,, f_name varchar(20) l_name varchar(20) )
For create table in database using PHP webpage; first conncet to database then use below code.
connect-db.php
Connect to database
<?php $server = 'localhost'; $user = 'user_name'; $pass = 'password'; $db = 'database_name'; // Connect to Database $connection = mysqli_connect($server, $user, $pass) or die("Could not connect to server ... \n" . mysqli_error ()); // select database mysqli_select_db($db) or die("Could not connect to database ... \n" . mysqli_error ()); ?>
create-table.php
Create Table in database
<?php include 'connect-db.php'; $sql = "id int(5) NOT NULL auto_increment, f_name varchar(20), l_name varchar(20)"; $result = mysqli_query($conn, $sql); if($result) { echo "Table user created successfully......"; } else { echo "Could not create table: ". mysqli_error($conn); } mysqli_close($conn); ?>
Output
Table user created successfully......
Google Advertisment