views:

586

answers:

2

Hi - 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?

A: 

check the generated sql query in the log. Maybe you have to put the where clause after the join.

erenon
+4  A: 

The problem is the uid=? in your WHERE clause. As a uid column is in both tables user_id and user_details MySQL cannot determine which column you really want to use. You must therefore do

// [...]
->where('user_id.uid=?', $uid)
// [...]
Stefan Gehrig
+1, from what I gather that should solve it.
karim79
thanks, sorry for the silly mistake!
daniel