saftutorials.com
MYSQL CREATE TABLE

You have to do the same thing for creating database tables what you did for creating a database. First, create the MySQL query for creating database tables and then execute the query in mysql_query function.


Below is an example for creating database tables

<?php
$database_host = 'localhost:3036';
$database_user = 'root';
$database_pass = '';
$conn = mysql_connect($database_host, $database_user, $database_pass);
if(! $conn ) {
 die('Could not connect: ' . mysql_error());
}else{
 echo 'Connected successfully\n';
}
$sql = 'CREATE TABLE student( '.
'student_id INT NOT NULL AUTO_INCREMENT, '.
'student_name VARCHAR(20) NOT NULL, '.
'student_address  VARCHAR(20) NOT NULL, '.
'student_enrollment_no   INT NOT NULL, '.
'join_date    timestamp(14) NOT NULL, '.
'primary key ( student_id ))';
$selected_or_not = mysql_select_db( 'xyz_school' );
if(! $selected_or_not ) {
 die('Not Selected xyz_school database');
}else{
 echo 'Selected xyz_school database';
}
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not create table: ' . mysql_error());
}
echo "Table student created successfully\n";
mysql_close($conn);
?>

Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic