带有表别名的PHP LEAP ORM查询

时间:2014-07-07 17:50:07

标签: php kohana-3 kohana-orm

目前我正在使用LEAP ORM for kohana并尝试创建一些SQL查询。这些查询针对oracle数据库。我能够成功连接和查询此数据库。但是,当我尝试使用这些别名对表和别引用列进行别名时,语法不起作用。以下是我目前的情况

     return $this->db->query("select HRB.PARENT_COMPANY 
FROM COMPANY_TABLE HRB 
INNER JOIN 
OTHER_TABLE BTR 
HRB.ID = BTR.WID 
WHERE HRB.NAME LIKE '".$VAL."%;");

似乎不喜欢HRB.PARENT

错误消息

ErrorException [ Warning ]: oci_execute(): ORA-00904: "GPR"."GIS_PROP_FCNB_1": invalid identifier
MODPATH\leap\classes\Base\DB\Oracle\DataReader\Standard.php [ 57 ]
52          throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => $reason));
53      }
54      if ( ! is_integer($mode)) {
55          $mode = 32;
56      }
57      if ( ! oci_execute($command, $mode)) {
58          $error = @oci_error($command);
59          $reason = (is_array($error) AND isset($error['message']))
60              ? $error['message']
61              : 'Unable to perform command.';
62          throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => $reason));

如果删除了表别名,则抛出以下错误

ErrorException [ Warning ]: oci_execute(): ORA-00918: column ambiguously defined

1 个答案:

答案 0 :(得分:1)

This page表示DB_ORM不支持表别名。

试试这个:

return $this->db->query("select COMPANY_TABLE.PARENT_COMPANY 
FROM COMPANY_TABLE
INNER JOIN OTHER_TABLE COMPANY_TABLE.ID = OTHER_TABLE.WID 
WHERE OTHER_TABLE.NAME LIKE '".$VAL."%;");