获取URL数据时遇SQL语法错误,求助排查MariaDB脚本语法问题
Fixing MariaDB SQL Syntax Error with Table References
Hey there, let's work through this syntax error you're facing! The core issue here is mixing up PHP object syntax with valid SQL syntax, plus an incomplete join condition.
What's Causing the Error?
Looking at your error message snippet:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '->ab_staff as staff join wpdb->users as users on staff.wp_user_id = users.' at line 1
There are two key problems here:
- The
->operator is PHP syntax for accessing object properties/methods (like when using WordPress's$wpdbobject), but in raw SQL, you need to use a period (.) to reference database-table or table-field relationships. - Your join condition cuts off at
users.— you're missing the actual field name from theuserstable that links tostaff.wp_user_id.
Corrected SQL Example
Assuming wpdb is your database name, ab_staff and users are tables within it, and users.ID is the matching field for staff.wp_user_id, here's the fixed syntax:
-- Example query (adjust SELECT fields as needed) SELECT staff.*, users.user_login, users.display_name FROM ab_staff AS staff JOIN wpdb.users AS users ON staff.wp_user_id = users.ID;
Additional Notes
- If
ab_staffis also part of thewpdbdatabase, you can explicitly write it aswpdb.ab_stafffor clarity, though it's optional if you've already setwpdbas your active database. - Double-check that the field names match exactly (SQL is case-sensitive on some systems) — make sure
staff.wp_user_idactually maps to a valid field in theuserstable (likeIDor another user identifier).
内容的提问来源于stack exchange,提问作者Coder321
相关产品推荐
相关产品推荐

