zend db 连接结果集
我使用 zend_db_select 来连接 3 个表,并且在结果集数组中,当我期望看到带有别名的列名时,它返回一个带有没有别名的键的数组。
$dbSelect = $db->select()->from(array("pp"=>"products_photos"),array())
->joinInner(array("ph"=>"photos"), "pp.photo_id=ph.photo_id","ph.photo_id")
->joinInner(array('pr'=>'products'),"pr.product_id=pp.product_id","pr.product_id")
->where("pr.product_id=$row->product_id");
$photoJoinRowSet = $db->fetchAll($dbSelect);
var_dump($photoJoinRowSet);die();
结果如下:
array(2) { [0]=> array(3) { ["product_id"]=> string(1) "1" ["photo_id"]=> string(1) "4" }}
当我期待时:
array(2) { [0]=>; array(3) { ["pr.product_id"]=>;字符串(1) "1" ["ph.photo_id"]=> string(1) "4" }}
......即带有列别名。
有谁知道为什么会发生这种情况?谢谢。
I used zend_db_select for joining 3 tables, and in the result set array while I was expecting to see the column names with aliases, it returns an array with keys having no aliases.
$dbSelect = $db->select()->from(array("pp"=>"products_photos"),array())
->joinInner(array("ph"=>"photos"), "pp.photo_id=ph.photo_id","ph.photo_id")
->joinInner(array('pr'=>'products'),"pr.product_id=pp.product_id","pr.product_id")
->where("pr.product_id=$row->product_id");
$photoJoinRowSet = $db->fetchAll($dbSelect);
var_dump($photoJoinRowSet);die();
RESULT LIKE :
array(2) { [0]=> array(3) { ["product_id"]=> string(1) "1" ["photo_id"]=> string(1) "4" }}
While I was expecting :
array(2) { [0]=> array(3) { ["pr.product_id"]=> string(1) "1" ["ph.photo_id"]=> string(1) "4" }}
......i.e with column aliases.
Does anyone know why this happens?? thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有在此处指定任何别名,因此您的选择将转换为类似
SELECT ph.photo_id, pr.product_id
的内容,不带AS
,这将返回photo_id
和product_id
正如预期的那样。如果您想要键中的点,您需要明确指定别名:
有关 Zend_Db_Select 文档。
You didn't specify any aliases here, so your select will translate to something like
SELECT ph.photo_id, pr.product_id
, withoutAS
, which will returnphoto_id
andproduct_id
as expected.You need to specify explicitly your aliases if you want the dots in the keys:
More information on the Zend_Db_Select documentation.