For the updated way to do this, see Create Table With PHP in Existing MySQL Database.
Create a MySQL database table using only PHP, for an existing database.
$dbhost = 'your.db.host';// you database host name goes here
$dbuser = 'databaseUsername';// you database username goes here
$dbpass = 'databasePassword';// you database password goes here
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$sql = 'CREATE TABLE clients( '.// edit table name here. Mine is 'clients'
/* do your fields */
'P_Id int NOT NULL AUTO_INCREMENT, '.
'field1 VARCHAR(40) NOT NULL, '.
'field2 VARCHAR(7) NOT NULL, '.
'field3 VARCHAR(20) NOT NULL, '.
'field4 VARCHAR(2) NOT NULL, '.
'field5 VARCHAR(4) NOT NULL, '.
'primary key ( P_Id ))';
mysql_select_db('yourDatabaseName');// your existing database name here
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not create table: ' . mysql_error());
}
echo "Table clients created successfully\n";// edit table name here. Mine is 'clients'
mysql_close($conn);
Questions and Comments are Welcome