Skip to content

Commit

Permalink
Add note into docs about starting with 0 in QueryBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Feb 8, 2014
1 parent faa3d22 commit 79d04ee
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions docs/en/reference/query-builder.rst
Expand Up @@ -39,9 +39,15 @@ input to any of the methods of the QueryBuilder and use the placeholder
->select('u.id', 'u.name')
->from('users', 'u')
->where('u.email = ?')
->setParameter(1, $userInputEmail)
->setParameter(0, $userInputEmail)
;
.. note::

Due to an API design error the numerical parameters in the QueryBuilder API
start with the needle ``0``, not with ``1`` as in the PDO API. This is very
unfortunate, but we have found no BC way to fix this.

Building a Query
----------------

Expand Down Expand Up @@ -202,8 +208,8 @@ done with the ``values()`` method on the query builder:
'password' => '?'
)
)
->setParameter(1, $username)
->setParameter(2, $password)
->setParameter(0, $username)
->setParameter(1, $password)
;
// INSERT INTO users (name, password) VALUES (?, ?)
Expand All @@ -219,8 +225,8 @@ Setting single values instead of all at once is also possible with the
->insert('users')
->setValue('name', '?')
->setValue('password', '?')
->setParameter(1, $username)
->setParameter(2, $password)
->setParameter(0, $username)
->setParameter(1, $password)
;
// INSERT INTO users (name, password) VALUES (?, ?)
Expand All @@ -237,14 +243,14 @@ Of course you can also use both methods in combination:
'name' => '?'
)
)
->setParameter(1, $username)
->setParameter(0, $username)
;
// INSERT INTO users (name) VALUES (?)
if ($password) {
$queryBuilder
->setValue('password', '?')
->setParameter(2, $password)
->setParameter(1, $password)
;
// INSERT INTO users (name, password) VALUES (?, ?)
}
Expand Down Expand Up @@ -276,7 +282,7 @@ user-input:
->update('users', 'u')
->set('u.logins', 'u.logins + 1')
->set('u.last_login', '?')
->setParameter(1, $userInputLastLogin)
->setParameter(0, $userInputLastLogin)
;
Building Expressions
Expand Down

0 comments on commit 79d04ee

Please sign in to comment.