The SQL statement generated by the thinkphp3.1 View model cannot be executed.

Source: Internet
Author: User
The SQL statement generated by the thinkphp3.1 View model cannot be executed in an order system and cannot be printed when the view model is used.
Custom View model
 Array ('id', 'orderno', 'date', 'Money', 'memo', 'State', '_ type' => 'left '), 'client' => array ('clientname', '_ on' => 'order. client_id = client. ID', '_ type' => 'right'), 'user' => array ('username',' _ on' => 'order. user_id = user. ID'),) ;}?>


Table structure









After the following statements are executed, a blank area is printed.
$Model = D("OrderView");$result = $Model->select();p($result);die;


After viewing the log file, the generated SQL statement is
SELECT order.id AS id,order.orderNo AS orderNo,order.date AS date,order.money AS money,order.memo AS memo,order.state AS state,client.clientName AS clientName,user.userName AS userName FROM or_order order LEFT JOIN or_client client ON order.client_id=client.id RIGHT JOIN or_user user ON order.user_id=user.id 


Please help me. This is a design experiment at the end of the project. it will take a few days to complete. it is very urgent. thank you!


Reply to discussion (solution)

The automatic table prefix has been added to the config file.

What is the problem with the execution of the generated SQL statement?

What is the problem with the execution of the generated SQL statement?


Error message
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left JOIN or_client client ON order. client_id = client. id right join or_user user 'at line 1

Do not use order for table aliases,
Order is the keyword ~

Do not use order for table aliases,
Order is the keyword ~


Thanks for your success.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.