gpt4 book ai didi

php - sql 适用于 phpmyadmin 但不适用于 php 脚本

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:50 27 4
gpt4 key购买 nike

我有 2 个表名类(class)和机构。这是我的查询:

CREATE TEMPORARY TABLE 
IF NOT EXISTS temp AS (SELECT course_name, ins_name
FROM courses
where course_name='ACCA') ;

select institution.ins_name, address, contact, website,
email from institution join temp on institution.ins_name = temp.ins_name

这是我的 php 脚本:

<?php
session_start();
include('db_connect.php');
$sql="CREATE TEMPORARY TABLE
IF NOT EXISTS temp AS (SELECT course_name, ins_name
FROM courses
where course_name='ACCA') ;

select institution.ins_name, address, contact, website, email from institution join temp on institution.ins_name = temp.ins_name";

$result= mysqli_query($conn, $sql) or die("MySQL error: " . mysqli_error($conn));

while ($row = mysqli_fetch_array($result)){

echo "<tr>";
echo "<td>" . $row['ins_name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['email'] . "</td>";

echo "</tr>";
}
echo "</table>"

?>

我不知道问题出在哪里。我得到的错误是:

MySQL 错误:您的 SQL 语法有误;检查与您的 MySQL 服务器版本相对应的手册,以了解在第 6 行的“select institution.ins_name, address, contact, website, email from institution j”附近使用的正确语法

我做错了什么?

最佳答案

来自 Multiple Statements :

MySQL optionally allows having multiple statements in one statement string. Sending multiple statements at once reduces client-server round trips but requires special handling.

Multiple statements or multi queries must be executed with mysqli_multi_query(). The individual statements of the statement string are separated by semicolon. Then, all result sets returned by the executed statements must be fetched.

或者,只需触发两个查询。

关于php - sql 适用于 phpmyadmin 但不适用于 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37543918/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com