Home  >  Article  >  Database  >  PHP and MYSQL database connections and tables created only once (if it doesn't already exist)?

PHP and MYSQL database connections and tables created only once (if it doesn't already exist)?

WBOY
WBOYforward
2023-08-31 17:33:031069browse

PHP 和 MYSQL 数据库连接和表创建仅一次(如果它尚不存在)?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete