Skip to content

docs: fix getCompiledInsert() explanation in query_builder.rst #5380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions user_guide_src/source/database/query_builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -886,25 +886,23 @@ Example::
'date' => 'My date',
];

$sql = $builder->set($data)->getCompiledInsert('mytable');
$sql = $builder->set($data)->getCompiledInsert();
echo $sql;

// Produces string: INSERT INTO mytable (`title`, `name`, `date`) VALUES ('My title', 'My name', 'My date')

The second parameter enables you to set whether or not the query builder query
The first parameter enables you to set whether or not the query builder query
will be reset (by default it will be--just like ``$builder->insert()``)::

echo $builder->set('title', 'My Title')->getCompiledInsert('mytable', false);
echo $builder->set('title', 'My Title')->getCompiledInsert(false);

// Produces string: INSERT INTO mytable (`title`) VALUES ('My Title')

echo $builder->set('content', 'My Content')->getCompiledInsert();

// Produces string: INSERT INTO mytable (`title`, `content`) VALUES ('My Title', 'My Content')

The key thing to notice in the above example is that the second query did not
utilize ``$builder->from()`` nor did it pass a table name into the first
parameter. The reason this worked is that the query has not been executed
The reason the second query worked is that the query has not been executed
using ``$builder->insert()`` which resets values or reset directly using
``$builder->resetQuery()``.

Expand Down