Home >Database >Mysql Tutorial >PHP and MYSQL database connections and tables created only once (if it doesn't already exist)?
To create the database only once, use the following syntax.
CREATE DATABASE IF NOT EXISTS yourDatabaseName;
To create a table only once, use the following syntax -
CREATE TABLE IF NOT EXISTS yourTableName ( yourColumnName yourDatatype, . . . N );
Let us implement the above two syntaxes to create it only once if the database and table does not exist -
mysql> CREATE DATABASE IF NOT EXISTS login; Query OK, 1 row affected (0.23 sec)
The above query successfully created the database.
The following is the query to create a table -
mysql> CREATE TABLE IF NOT EXISTS DemoTable ( Id int ); Query OK, 0 rows affected (0.56 sec)
The above query successfully created a table.
The above is the detailed content of PHP and MYSQL database connections and tables created only once (if it doesn't already exist)?. For more information, please follow other related articles on the PHP Chinese website!