Skip to content

Commit

Permalink
Document that addSql Can Take Params and Types
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguitarguy committed Jul 5, 2016
1 parent 7eac3f8 commit 74f21c1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions en/reference/migration_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,38 @@ custom SQL queries:
$this->addSql('DROP TABLE addresses');
}
}
Additionally, ``addSql()`` can take parameters and types as its second and third
arguments. For instance, you might want to bind values to to named (or question
mark) SQL parameters.

.. code-block:: php
namespace DoctrineMigrations;
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;
class Version20160705000000 extends AbstractMigration
{
public function up(Schema $schema)
{
// ...
$this->addSql('INSERT INTO addresses (street) VALUES (:street)', [
'street' => '123 Example Lane',
], [
'string' => 'string',
]);
}
public function down(Schema $schema)
{
$this->addSql('DROP TABLE addresses');
}
}
See the `Doctrine DBAL documentation <http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html>`_
for more information on binding types and more information about the placeholder
syntax.

0 comments on commit 74f21c1

Please sign in to comment.