Home  >  Article  >  Backend Development  >  thinkphp3.1视图模型生成的SQL语句执行不了

thinkphp3.1视图模型生成的SQL语句执行不了

WBOY
WBOYOriginal
2016-06-23 13:42:101063browse

在做一个订单系统,在用视图模型的时候打印不出东西。
自定义的视图模型

<?php//订单视图Class OrderViewModel extends ViewModel{	public $viewFields = array(		'order' => 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'), 	);	}?>


表结构









执行了下列语句之后,打印出一片空白
$Model = D("OrderView");		$result = $Model->select();		p($result);die;


查看日志文件后,生成的SQL语句是
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 


请各位大神帮帮忙。这是一个期末设计性实验,还有几天就要交了,万分紧急,谢谢!


回复讨论(解决方案)

已在config文件中加了自动表前缀

生成的sql语句执行有什么问题?

生成的sql语句执行有什么问题?


错误信息
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

表的别名不要用order,
order是关键字~

表的别名不要用order,
order是关键字~


照你说的真的成功了,万分感谢
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn