SQL脚本可在MySQL中运行,但无法运行mysqli-> query();为什么? [英] SQL script works in MySQL, but fails with mysqli->query(); why?

查看:275
本文介绍了SQL脚本可在MySQL中运行,但无法运行mysqli-> query();为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SQL脚本在MySQL Workbench中成功运行.

My SQL script works successfully in MySQL Workbench.

以下给出了错误:

$link = mysqli_connect(***********);
$result = $link->query($sql);

SQL脚本执行一些操作,包括:

The SQL script performs some actions including:

  • 创建临时表
  • 截断表
  • 放置表格
  • 插入
  • 选择

错误是:

-- 1.1 Creating temporary table for categories

    drop table if exists exp_categories; -- just in case
    create temporary table exp_categories
    (
        ID bigint not null,
        Categories text not null,
        PRIMARY KEY (ID)
    ) DEFAULT CHARSET=utf8;

-- 1.2 Inserting data...
-- few other statements here
-- last statement is SELECT

mysqli是否有我遇到的限制?

Does mysqli have limitations that I am encountering?

推荐答案

尝试使用multi_query()

必须使用以下命令执行多个语句或多个查询 mysqli_multi_query().陈述的个别陈述 字符串用分号分隔.

Multiple statements or multi queries must be executed with mysqli_multi_query(). The individual statements of the statement string are separated by semicolon.

$link->multi_query($sql)

与您连接的用户必须在数据库中具有必要的特权或全局特权.

And the user you connect with have to have necessary privileges in your db or global privileges.

这篇关于SQL脚本可在MySQL中运行,但无法运行mysqli-> query();为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆