简体   繁体   English

工作的MySQL查询在Perl中失败

[英]Working MySQL Query fails in Perl

I have a query, which when run from within phpMyAdmin, it works, however when integrated within a website written in Perl, it fails and throws errors. 我有一个查询,当从phpMyAdmin中运行时,它可以工作,但是,当集成到用Perl编写的网站中时,它会失败并引发错误。 Both are run with a connection to the same database, and from coding/formatting side when integrated into the Website, all is correct and the same as other queries. 两者都在同一个数据库的连接上运行,并且在集成到网站中时从编码/格式化方面来说,都是正确的,并且与其他查询相同。

Any help with this would be much appreciated - Thanks! 任何帮助,将不胜感激-谢谢!

MySQL Query: MySQL查询:

CREATE TEMPORARY TABLE tmp_lecture_days (
timeslot_id int(50)
);
INSERT INTO tmp_lecture_days (timeslot_id)
SELECT DISTINCT tab_appointment.timeslot_id
FROM tab_appointment WHERE lecture_id = '1115';
SELECT COUNT(timeslot_id)
FROM tmp_lecture_days;

MySQL Query in Perl: Perl中的MySQL查询:

            $query
                = &statement_database(
                    "CREATE TEMPORARY TABLE tmp_lecture_days (
                    timeslot_id int(50)
                    );
                    INSERT INTO tmp_lecture_days (timeslot_id)
                    SELECT DISTINCT tab_appointment.timeslot_id
                    FROM tab_appointment WHERE lecture_id = '1115';
                    SELECT COUNT(timeslot_id)
                    FROM tmp_lecture_days;");

             my ($days) = $query->fetchrow_array;

Error Log: 错误日志:

7.3.2011 10:14:12 error You have an error in your SQL syntax; 7.3.2011 10:14:12错误您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 检查与您的MySQL服务器版本相对应的手册,以在'附近使用正确的语法; 7.3.2011 10:14:12 error INSERT INTO tmp_lecture_days (timeslot_id) 7.3.2011 10:14:12 error SELECT DISTINCT tab_appoi' at line 3 7.3.2011 10:14:12错误INSERT INTO tmp_lecture_days(timeslot_id)7.3.2011 10:14:12错误SELECT DISTINCT tab_appoi'在第3行

If you are using DBI for running the query, you are not allowed to put more than one statement into it. 如果使用DBI来运行查询,则不允许在其中添加多个语句。 Try putting CREATE TABLE ... into one query and INSERT ... into another. 尝试将CREATE TABLE ...放入一个查询,将INSERT ...放入另一个查询。

I think the following query is equivalent to the 3 queries: 我认为以下查询等同于3个查询:

SELECT COUNT(DISTINCT timeslot_id) FROM tab_appointment
    WHERE lecture_id = '1115'

For more details, check the MySQL reference manual for COUNT() here . 有关更多详细信息,请在此处查看MySQL参考手册中的COUNT()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM