Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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 mysqli中无效,但在MySQL CLI中无效。_Php_Mysql_Mysqli - Fatal编程技术网

特定查询语法在php mysqli中无效,但在MySQL CLI中无效。

特定查询语法在php mysqli中无效,但在MySQL CLI中无效。,php,mysql,mysqli,Php,Mysql,Mysqli,当我尝试在PHP mysqli中执行此查询时,但在MySQL CLI中执行时,此查询会出现语法错误。有人能告诉我这里发生了什么事吗 问题是: DROP TABLE IF EXISTS `wp_commentmeta`; CREATE TABLE `wp_commentmeta` ( `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `comment_id` bigint(20) unsigned NOT

当我尝试在PHP mysqli中执行此查询时,但在MySQL CLI中执行时,此查询会出现语法错误。有人能告诉我这里发生了什么事吗

问题是:

DROP TABLE IF EXISTS `wp_commentmeta`;
    CREATE TABLE `wp_commentmeta` (
      `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
      `meta_key` varchar(255) DEFAULT NULL,
      `meta_value` longtext,
      PRIMARY KEY (`meta_id`),
      KEY `comment_id` (`comment_id`),
      KEY `meta_key` (`meta_key`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
以下是测试代码:

<?php

$sql="
    DROP TABLE IF EXISTS `wp_commentmeta`;
    CREATE TABLE `wp_commentmeta` (
      `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
      `meta_key` varchar(255) DEFAULT NULL,
      `meta_value` longtext,
      PRIMARY KEY (`meta_id`),
      KEY `comment_id` (`comment_id`),
      KEY `meta_key` (`meta_key`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";

$conn=mysqli_connect('localhost','root','yesthereis','test');
if(mysqli_query($conn, $sql)){
    echo "Inserted\n";
}else{
    echo "Failed\n".mysqli_error($conn)."\n";
}
?>
如您所见,它在CLI中运行良好:

jgalley@jgalley-debian:~/code/mysqlsync2$ mysql -u root -p'yesthereis' test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 213
Server version: 5.1.63-0+squeeze1 (Debian)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> DROP TABLE IF EXISTS `wp_commentmeta`;
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql>     CREATE TABLE `wp_commentmeta` (
    ->       `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    ->       `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->       `meta_key` varchar(255) DEFAULT NULL,
    ->       `meta_value` longtext,
    ->       PRIMARY KEY (`meta_id`),
    ->       KEY `comment_id` (`comment_id`),
    ->       KEY `meta_key` (`meta_key`)
    ->     ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

不能在一个mysqli\u查询调用中运行两个查询。将查询字符串一分为二并分别执行。或者,正如他们在评论中正确指出的那样,使用mysqli\u multi\u查询作为脚本中mysqli\u查询的替代品


这有助于减少SQL注入。

您不能在一个mysqli\u查询调用中运行两个查询。将查询字符串一分为二并分别执行。或者,正如他们在评论中正确指出的那样,使用mysqli\u multi\u查询作为脚本中mysqli\u查询的替代品

这有助于减少SQL注入。

除非您使用
jgalley@jgalley-debian:~/code/mysqlsync2$ mysql -u root -p'yesthereis' test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 213
Server version: 5.1.63-0+squeeze1 (Debian)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> DROP TABLE IF EXISTS `wp_commentmeta`;
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql>     CREATE TABLE `wp_commentmeta` (
    ->       `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    ->       `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->       `meta_key` varchar(255) DEFAULT NULL,
    ->       `meta_value` longtext,
    ->       PRIMARY KEY (`meta_id`),
    ->       KEY `comment_id` (`comment_id`),
    ->       KEY `meta_key` (`meta_key`)
    ->     ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye