Zend_db 中的完整性约束违规
我有以下代码:
$selectColumns= array('user_id.user_email',
'user_details.first_name',
'user_details.last_name',
'user_details.zip',
'user_details.store_id');
$result = $handle->select()->from('user_id')
->where('uid=?', $uid)
->columns($selectColumns)
->join('user_details', 'user_id.uid = user_details.uid')
->query(ZEND_DB::FETCH_OBJ);
运行后,出现以下错误:
Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: '
Integrity constraint violation: 1052 Column 'uid' in where clause is ambiguous
我一直在试图找出我做错了什么。 有什么帮助吗?
I have the following code:
$selectColumns= array('user_id.user_email',
'user_details.first_name',
'user_details.last_name',
'user_details.zip',
'user_details.store_id');
$result = $handle->select()->from('user_id')
->where('uid=?', $uid)
->columns($selectColumns)
->join('user_details', 'user_id.uid = user_details.uid')
->query(ZEND_DB::FETCH_OBJ);
After I run, I get the following error:
Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: '
Integrity constraint violation: 1052 Column 'uid' in where clause is ambiguous
I've been trying to figure out what I'm doing wrong.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题出在
WHERE
子句中的uid=?
。 由于uid
列同时存在于user_id
和user_details
表中,MySQL 无法确定您真正想要使用哪一列。 因此你必须这样做The problem is the
uid=?
in yourWHERE
clause. As auid
column is in both tablesuser_id
anduser_details
MySQL cannot determine which column you really want to use. You must therefore do检查日志中生成的sql查询。 也许您必须在连接之后放置 where 子句。
check the generated sql query in the log. Maybe you have to put the where clause after the join.