Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果数据库中不存在,则创建新表_Php_Mysql - Fatal编程技术网

Php 如果数据库中不存在,则创建新表

Php 如果数据库中不存在,则创建新表,php,mysql,Php,Mysql,我在数据库中有一个命名客户的表。该表共有83列。我想创建另一个NewCustomers表,类似于使用php和mysql查询的Customers。如果数据库中存在NewCustomers表,则无需创建该表。如果不存在,则将创建NewCustomers表。 我知道有一个疑问 CREATE TABLE 'NewCustomers' LIKE 'Customers'; 但只有在新客户不存在的情况下,它才会创建类似于表的客户。我如何使用 IF NOT EXISTS 在这方面??我不想把83列的名字写得

我在数据库中有一个命名客户的表。该表共有83列。我想创建另一个NewCustomers表,类似于使用php和mysql查询的Customers。如果数据库中存在NewCustomers表,则无需创建该表。如果不存在,则将创建NewCustomers表。 我知道有一个疑问

CREATE TABLE 'NewCustomers' LIKE 'Customers';
但只有在新客户不存在的情况下,它才会创建类似于表的客户。我如何使用

IF NOT EXISTS
在这方面??我不想把83列的名字写得像这样

CREATE TABLE IF NOT EXISTS `NewCustomers` (
        `id` int(11) NOT NULL auto_increment,
        'name` varchar(250)  NOT NULL,    
        `data` varchar(100) NOT NULL default '',
        .
        .
        .
        PRIMARY KEY  (`id`)
)

像这样做很简单

CREATE TABLE IF NOT EXISTS `NewCustomers` like `Customers`
注:

同时,可以安全地引用下面的DB名称

CREATE TABLE IF NOT EXISTS `NewCustomers` like `DB_name`.`Customers`

很高兴它能帮助你:@ALMAKSUD