pTutorial

New way to learn PHP

PHP 5 Table creation

How to create Table in a database?

We can use the CREATE TABLE statement to the mysql_query() function to execute the command.

Creating Table

CREATE TABLE student (
name VARCHAR(30) NOT NULL,
roll-no VARCHAR(30) NOT NULL,
);

Create table example

<?php

$host = 'localhost';
$user = 'root';
$password="";
$db_con = mysql_connect($host, $user, $password);
mysql_select_db( 'my_db1' );
$sql = "CREATE TABLE student( ".
       "id INT NOT NULL AUTO_INCREMENT, ".
       "name VARCHAR(20) NOT NULL, ".
       "branch VARCHAR(40) NOT NULL, ".
       "PRIMARY KEY ( id )); ";
$qu = mysql_query( $sql, $db_con );
if(! $qu )
{
  die('table not created: ' . mysql_error());
}
echo "Table created successfully\n";
mysql_close($db_con);

?>

Output

Table created successfully

Step by step process of creating table using WAMP server

1. After creating database, you are ready to create table.

2. Click on database that are created by you shown in the left side.

3. Appear following window.

create table | php tutorial

4. Type table name, number of column and click go to create.

5. Appear following window.

create table using WAMP | php tutorial

6. Fill the details like name, data type as per your need and click save button.

php tutorial

7. Table has been created successfully.

8. If you want to see the structure of table click on structure on menu bar.

Create table using wamp php

Now you are ready to store data on database but don't forget the database and table name.


QUOTES OF THE DAY

The basis of all progress is self-reliance

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER