Create Mysql Table With Php

Description: Good for install scripts or automated table building.

<?PHP
 
$table_def  = "id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,";
$table_def .= "student_id INT(11) NOT NULL,";
$table_def .= "f_name TINYTEXT NOT NULL,";
$table_def .= "l_name TINYTEXT NOT NULL,";
$table_def .= "supervisor TINYTEXT NOT NULL,";
$table_def .= "building TINYTEXT NOT NULL,";
$table_def .= "email TINYTEXT NOT NULL,";
$table_def .= "score SMALLINT(6) NULL,";
$table_def .= "stamp DATETIME NOT NULL,";
$table_def .= "UNIQUE KEY id (id)";
 
IF (!@MYSQL_QUERY ("CREATE TABLE $tablename ($table_def)")) {
     ECHO "The database table, '$tablename', could not be created.";
} ELSE {
     ECHO "Successfully created the '$tablename' table.";
}
 
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.