Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-804

[GH-523] SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
    • Environment:
      OSX 10.8, PHP5.4, MySQL56

      Description

      I am using this code from documentation

      QueryBuilder Positional with ?
      $query = $this->subject->getDatabaseHandle()->createQueryBuilder();
      $query->delete($this->testTable)->where($this->testFieldSecond . ' = ?')
      $query->setParameter(1, (int)$GLOBALS['EXEC_TIME']);
      $query->execute();
      

      ... and I also tried

      QueryBuilder Positional with ?1
      $query = $this->subject->getDatabaseHandle()->createQueryBuilder();
      $query->delete($this->testTable)->where($this->testFieldSecond . ' = ?1')
      $query->setParameter(1, (int)$GLOBALS['EXEC_TIME']);
      $query->execute();
      

      but I got this error:

      Error in test case deletePositionalParameter
      File: vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php
      Line: 91
      An exception occurred while executing 'DELETE FROM test_t3lib_dbtest WHERE fieldblub = ?' with params [1391699318]:
      
      SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
      

      When I provide a type to setParamter like

      QueryBuilder Positional with ?1 and type
      $query = $this->subject->getDatabaseHandle()->createQueryBuilder();
      $query->delete($this->testTable)->where($this->testFieldSecond . ' = ?1')
      $query->setParameter(1, (int)$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT);
      $query->execute();
      

      or when I changed it to a named query it works

      QueryBuilder Positional with named query
      $query = $this->subject->getDatabaseHandle()->createQueryBuilder();
      $query->delete($this->testTable)->where($this->testFieldSecond . ' = :test')
      $query->setParameter(':test', (int)$GLOBALS['EXEC_TIME']);
      $query->execute();
      

      Url: https://github.com/doctrine/dbal/pull/523

      Message:

      Creating Unit Tests to proof the behavior. Its my first PR and I
      don't know if I created the Unit Test in the right place. It was the
      location where the test actually writing to database which is needed
      provoke the error.

      DBAL-803 #Provides a test for this issue

        Issue Links

          Activity

          Hide
          Doctrine Bot added a comment -

          A related Github Pull-Request [GH-523] was closed:
          https://github.com/doctrine/dbal/pull/523

          Show
          Doctrine Bot added a comment - A related Github Pull-Request [GH-523] was closed: https://github.com/doctrine/dbal/pull/523
          Hide
          Benjamin Eberlei added a comment -

          Fixed in the docs.

          Show
          Benjamin Eberlei added a comment - Fixed in the docs.

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Doctrine Bot
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: