To Create a new Table in a MySqli Database you will have to be sure of the following. #mysql
- You Created A Database
- You Granted Privileges to the database
- Created a config.php file to access the database
- An id row
- A Description row
- A timestamp
id | description | timestamp |
values | values | values |
<?php include('config.php'); // sql to create table $sql = "CREATE TABLE about( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, description VARCHAR(250) NOT NULL, reg_date TIMESTAMP )"; if ($con->query($sql) === TRUE) { echo "Table about created successfully"; } else { echo "Error creating table: " . $con->error; } $con->close(); ?>If you are having trouble you may want to go back and check that you have access to the database and that you correctly set all the usernames and passwords correctly. Also make sure that you granted privileges to the user to access the database.
Create Multiple Tables in One Script php mysqli
include('config.php'); $sql = "CREATE TABLE IF NOT EXISTS `mytable` ( `id` int(6) unsigned NOT NULL AUTO_INCREMENT, `table1` varchar(250) NOT NULL, `table2` varchar(250) NOT NULL, `table3` varchar(250) NOT NULL, `table4` varchar(250) NOT NULL, `table5` varchar(250) NOT NULL, `table6` varchar(250) NOT NULL, `table7` varchar(250) NOT NULL, `table8` varchar(250) NOT NULL, `table9` int(9) NOT NULL, `table10` int(9) NOT NULL, `datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; "; if ($con->query($sql) === TRUE) { echo "Table fantasyplayers created successfully"; } else { echo "Error creating table: " . $con->error; }