Is it possible to get the SQL for a Doctrine 2 entity insert?
For example, let's say I have this:
$foo = new Foo();
$foo->setName('bar');
$em->persist($foo);
$em->flush();
Is there a way to get the SQL for the INSERT statement there? If so, how?
You could try the SQL-Logger:
$em->flush(); // to write cached stuff down and isolate the following
// activate logger
$em->getConnection()
->getConfiguration()
->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
$foo = new Foo();
$foo->setName('bar');
$em->persist($foo);
$em->flush();
// disable logger
$em->getConnection()
->getConfiguration()
->setSQLLogger(null);
It works with other DBMS than MySQL too. There are also other possibilities to write in files. Look here:
https://www.brunsware.de/blog/symfony/monolog-doctrine-logfile.html
http://vvv.tobiassjosten.net/symfony/logging-doctrine-queries-in-symfony2/
You could activate the query log in your MySQL server (guessing it's it) : in /etc/mysql/my.ini (usual place) :
[mysqld]
log=/tmp/mysql.log
then read this file where you will find each issued query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With