Home > Database > Mysql Tutorial > 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
Release: 2023-08-31 17:33:03
forward
1173 people have browsed it

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

To create the database only once, use the following syntax.

CREATE DATABASE IF NOT EXISTS yourDatabaseName;
Copy after login

To create a table only once, use the following syntax -

CREATE TABLE IF NOT EXISTS yourTableName
(
   yourColumnName yourDatatype,
   .
   .
   .
   N
);
Copy after login

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template