user1079425
user1079425

Reputation:

(ZEND) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]:

When I try to execute this Sql-Statement I have this error :

*Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_actualite' in where clause is ambiguous' in C:\wamp\www\contradictors\library\Zend\Db\Statement\Pdo.php on line 234*

Here is my code :

    <?php
        class Critique extends Zend_Db_Table
        {
             protected $_name = "Critique" ;

             public function select_critique($limit1, $limit2)
             {
                   $db = $this -> getDefaultAdapter() ;
                   $last_actu = $db -> select()
                                    -> order('id_actualite DESC')
                                    -> from('Actualite')
                                    -> limit($limit1) ;
                   $last_actu = $last_actu -> query() ;
                   $last_actu = $last_actu -> fetch() ;

                   $select = $db -> select()
                                 -> from('Critique')
                                 -> order('id_critique DESC')
                                 -> join('Actualite', 'Critique.id_actualite = Actualite.id_actualite')
                                 -> where('id_actualite = ' . $last_actu['id_actualite'])
                                 -> limit($limit2) ;
                  return $select -> query() ;
             }
        }
   ?>

I don't have any idea about this error :( thank you

Upvotes: 0

Views: 3666

Answers (1)

Baruch
Baruch

Reputation: 21498

You have two columns named id_actualite: Critique.id_actualite and Actualite.id_actualite, so the where clause

where('id_actualite = ' . $last_actu['id_actualite'])

is ambiguous. Try changing it to

where('Critique.id_actualite = ' . $last_actu['id_actualite'])

or

where('Actualite.id_actualite = ' . $last_actu['id_actualite'])

Upvotes: 2

Related Questions