简体   繁体   English

我的SQL查询有什么问题?

[英]What is wrong in my SQL query?

I have a query that joins two table, and it keeps getting the error. 我有一个连接两个表的查询,并且不断收到错误。

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1`. 查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ 0”附近使用。

I can't seem to figure out what is wrong here? 我似乎无法弄清楚这里出了什么问题?

I've already check this but in my case it is different. 我已经查这个 ,但我的情况是不同的。

Here is my query: 这是我的查询:

$sQuery = "SELECT SQL_CALC_FOUND_ROWS A.id, A.studentNum, B.lastName, B.firstName, B.middleName, B.year, B.courseBlock, B.status, A.facultyloading_id"+
          " FROM table_enrolledstudents AS A"+
          " INNER JOIN table_student AS B"+
          " ON A.studentNum = B.studentNum";  

What do you think is wrong? 你觉得错什么? Can you help me? 你能帮助我吗? Thank you! 谢谢!

Use the PHP string concatenation operator . 使用PHP字符串连接运算符. (dot). (点)。

Or to improve readability/maintainability you could also put the query into a single string with line breaks. 为了提高可读性/可维护性,您还可以将查询放入带有换行符的单个字符串中。

$sql = "SELECT SQL_CALC_FOUND_ROWS A.id, A.studentNum, B.lastName, B.firstName, B.middleName, B.year, B.courseBlock, B.status, A.facultyloading_id
        FROM table_enrolledstudents AS A
        INNER JOIN table_student AS B
        ON A.studentNum = B.studentNum";

Explanation: This is because PHPs type system allows arithmetic operations on strings (which can contain numbers), eg "1" + "2" would return the sum, which is 3 . 说明:这是因为PHPs类型系统允许对字符串(可以包含数字)进行算术运算,例如"1" + "2"将返回总和,即3 If a string used in an arithmetic operation does not contain a parsable number, then it is treated as zero, so the result of "abc" + 5 is 5 . 如果在算术运算中使用的字符串不包含可分析的数字,则将其视为零,因此"abc" + 5的结果为5

As Mr. Aleksander Bavdaz said, I have replaced the plus and make it a dot and the error is gone. 正如亚历山大·巴夫达兹(Aleksander Bavdaz)先生所说,我已将加号替换成一个点,并且错误消失了。 Here is my new query. 这是我的新查询。 Thank you for your help! 谢谢您的帮助!

$sQuery = "SELECT SQL_CALC_FOUND_ROWS A.id, A.studentNum, B.lastName, B.firstName, B.middleName, B.year, B.courseBlock, B.status, A.facultyloading_id".
                " FROM table_enrolledstudents AS A".
                " INNER JOIN table_student AS B".
                    " ON A.studentNum = B.studentNum"

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

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