You have an existing MySQL database and you want to create a table using only PHP. You want to use mysqli_query, not mysql_query. Do it like this, but edit line 2 and line 11:
/* edit with your own database details */ $link = mysqli_connect("db.host", "your_db_username", "db_password", "db_name"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* choose your own table name */ $tablename = "umpaloompa"; $sql = "CREATE TABLE $tablename ( `someid` INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, `field1` VARCHAR(25) NOT NULL, `field2` VARCHAR(18) NOT NULL, `field3` VARCHAR(45), `field4` TIMESTAMP ) CHARACTER SET utf8 COLLATE utf8_general_ci"; /* Create table */ if (mysqli_query($link, $sql) === TRUE) { printf("Table $tablename successfully created.\n"); } else { printf("Could not create Table $tablename.\n"); } mysqli_close($link);
Pingback: Create MySQL Table in Existing Database With PHP