Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
6e76a638
Commit
6e76a638
authored
Dec 21, 2013
by
Guilherme Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #454 from deeky666/add-querybuilder-insert-documentation
Add documentation for query builder insert operation
parents
89c7b527
698b1624
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
5 deletions
+87
-5
query-builder.rst
docs/en/reference/query-builder.rst
+87
-5
No files found.
docs/en/reference/query-builder.rst
View file @
6e76a638
...
@@ -46,8 +46,8 @@ Building a Query
...
@@ -46,8 +46,8 @@ Building a Query
----------------
----------------
The ``\Doctrine\DBAL\Query\QueryBuilder`` supports building ``SELECT``,
The ``\Doctrine\DBAL\Query\QueryBuilder`` supports building ``SELECT``,
``
UPDATE`` and ``DELETE`` queries. Which sort of query you are building
``
INSERT``, ``UPDATE`` and ``DELETE`` queries. Which sort of query you
depends on the methods you are using.
are building
depends on the methods you are using.
For ``SELECT`` queries you start with invoking the ``select()`` method
For ``SELECT`` queries you start with invoking the ``select()`` method
...
@@ -59,13 +59,18 @@ For ``SELECT`` queries you start with invoking the ``select()`` method
...
@@ -59,13 +59,18 @@ For ``SELECT`` queries you start with invoking the ``select()`` method
->select('u.id', 'u.name')
->select('u.id', 'u.name')
->from('users', 'u');
->from('users', 'u');
For ``UPDATE`` and ``DELETE`` queries you can pass the table name into
For ``INSERT``, ``UPDATE`` and ``DELETE`` queries you can pass the
the ``update($tableName)`` and ``delete($tableName)``:
table name into the ``insert($tableName)``, ``update($tableName)``
and ``delete($tableName)``:
.. code-block:: php
.. code-block:: php
<?php
<?php
$queryBuilder
->insert('users', 'u')
;
$queryBuilder
$queryBuilder
->update('users', 'u')
->update('users', 'u')
;
;
...
@@ -80,7 +85,8 @@ by calling ``$queryBuilder->getSQL()`` or casting the object to string.
...
@@ -80,7 +85,8 @@ by calling ``$queryBuilder->getSQL()`` or casting the object to string.
WHERE-Clause
WHERE-Clause
~~~~~~~~~~~~
~~~~~~~~~~~~
All 3 types of queries allow where clauses with the following API:
The ``SELECT``, ``UPDATE`` and ``DELETE`` types of queries allow where
clauses with the following API:
.. code-block:: php
.. code-block:: php
...
@@ -178,6 +184,82 @@ returned.
...
@@ -178,6 +184,82 @@ returned.
->setFirstResult(10)
->setFirstResult(10)
->setMaxResults(20);
->setMaxResults(20);
VALUES Clause
~~~~~~~~~~
For the ``INSERT`` clause setting the values for columns to insert can be
done with the ``values()`` method on the query builder:
.. code-block:: php
<?php
$queryBuilder
->insert('users')
->values(
array(
'name' => '?',
'password' => '?'
)
)
->setParameter(1, $username)
->setParameter(2, $password)
;
// INSERT INTO users (name, password) VALUES (?, ?)
Each subsequent call to ``values()`` overwrites any previous set values.
Setting single values instead of all at once is also possible with the
``setValue()`` method:
.. code-block:: php
<?php
$queryBuilder
->insert('users')
->setValue('name', '?')
->setValue('password', '?')
->setParameter(1, $username)
->setParameter(2, $password)
;
// INSERT INTO users (name, password) VALUES (?, ?)
Of course you can also use both methods in combination:
.. code-block:: php
<?php
$queryBuilder
->insert('users')
->values(
array(
'name' => '?'
)
)
->setParameter(1, $username)
;
// INSERT INTO users (name) VALUES (?)
if ($password) {
$queryBuilder
->setValue('password', '?')
->setParameter(2, $password)
;
// INSERT INTO users (name, password) VALUES (?, ?)
}
Not setting any values at all will result in an empty insert statement:
.. code-block:: php
<?php
$queryBuilder
->insert('users')
;
// INSERT INTO users () VALUES ()
Set Clause
Set Clause
~~~~~~~~~~
~~~~~~~~~~
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment