DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Install MySQL Table With PHP.

01.26.2007
| 1753 views |
  • submit to reddit
        To automatically install a table into MySQL with PHP.

<?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.";
}
?>