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
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
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.
.png)
4. Type table name, number of column and click go to create.
5. Appear following window.
.png)
6. Fill the details like name, data type as per your need and click save button.
.png)
7. Table has been created successfully.
8. If you want to see the structure of table click on structure on menu bar.
.png)
Now you are ready to store data on database but don't forget the database and table name.