1

I've checked my request many times and I don't understand why MySQL displays this error (SQLSTATE[HY093]: Invalid parameter number: parameter was not defined):

public function getOneBySlug($slug)
{
    $query = $this
        ->createQueryBuilder('c')
        ->select('partial c.{id, slug, name, description, imagePath, imageExt}')
        ->where('c.slug = :slug')
        ->setParameter('slug', $slug)
        ->getQuery()
        ->useResultCache(true, 300)
        ->getOneOrNullResult()
    ;

    return $query;
}

And the real request:

SELECT c0_.id AS id_0
     , c0_.slug AS slug_1
     , c0_.name AS name_2
     , c0_.description AS description_3
     , c0_.image_path AS image_path_4
     , c0_.image_ext AS image_ext_5
     , c0_.parent_id AS parent_id_6
FROM category_store c0_
WHERE c0_.slug = 'thing';

As you can see, there's a single parameter.

Thanks for your help.

waka
  • 3,362
  • 9
  • 35
  • 54
  • Possible duplicate of [PHP PDOException: "SQLSTATE\[HY093\]: Invalid parameter number"](https://stackoverflow.com/questions/18028706/php-pdoexception-sqlstatehy093-invalid-parameter-number) – Toni Vanhala Aug 10 '17 at 13:13
  • Your query looks okay. You are certain the error is coming from this section of code? You pasted in your actual code? Didn't "clean" it up for your question? – Cerad Aug 10 '17 at 13:17
  • Yes, I'm certain, the error is coming from this section of code. And no, didn't clean it up. –  Aug 10 '17 at 15:30
  • Whats the output of the query if you print it out ? – Noob Aug 10 '17 at 15:49
  • When I run the request directly in phpMyAdmin, the output is what is expected. –  Aug 10 '17 at 16:25

0 Answers0