Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute params with doctrine using named parameters

I'm encountering a strange problem with doctrine and named parameters.

Here is a query which actually works perfectly with this set of parameters (dynamic in my code):

$params = array(    ':id_editeur' => 1,
                    ':nom_editeur' => 'Test');

public function updateById($params)
{
    Doctrine_Query::create()
       ->update('Editeur e')
       ->set('e.nom_editeur', ':nom_editeur')
       ->where('e.id_editeur = :id_editeur')
       ->execute($params);
}

Now i have another function

public function findAll($params)
{
    $query = Doctrine_Query::create()
        ->from('Editeur e')
        ->orderBy(':orderby')
        ->limit(':limit')
        ->offset(':offset');

    return $query->execute($params);
}

With these parameters:

    $params = array(    ':orderby' => ('e.id_editeur ASC'),
                        ':limit' => (10),
                        ':offset' => (20));

And even if it's the same mechanism i get the following error

Invalid parameter number: number of bound variables does not match number of tokens

Any idea of the reason? By the way, it works if I fill the orderby, limit and offset directly in the function in the classical way.

like image 624
Simon Taisne Avatar asked Sep 13 '25 11:09

Simon Taisne


1 Answers

The params var cannot contain ":" character...

Try replacing:

$params = array(    ':id_editeur' => 1,
                ':nom_editeur' => 'Test');

to:

$params = array(    'id_editeur' => 1,
                'nom_editeur' => 'Test');
like image 172
Pipe Avatar answered Sep 16 '25 00:09

Pipe