Creating database table using php
use sql query to create tables in the particulardatabase using mysql_query() function See the below example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php $databasehost = 'localhost'; $databaseuser = 'root'; $databasepassword = ''; $connection = mysql_connect($databasehost, $databaseuser, $databasepassword); if(! $connection ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; $sqlqry = 'CREATE TABLE mydoubts_data( '. 'id INT NOT NULL AUTO_INCREMENT, '. 'name VARCHAR(20) NOT NULL, '. 'primary key (id ))'; mysql_select_db('mydoubts'); $output = mysql_query( $sqlqry, $connection); if(! $output) { die('Could not create table: ' . mysql_error()); } echo "Table employee created successfully\n"; mysql_close($connection); ?> |
or you can use the phpmyadmin to create table in the particular database.