Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Doctrine ORM nativeQuery: How to rename table

I’m trying to rename a table with nativeQuery like this:

$rsm = new ResultSetMapping();
$query = $em->createNativeQuery('RENAME TABLE `'.$oldname.'` TO `'.$newname.'`', $rsm);
$result = $query->getResult();

Strangely the table gets renamed, but the last line throws an error:

Undefined offset: 1
.\vendor\doctrine\dbal\src\Driver\PDO\Exception.php:20
.\vendor\doctrine\dbal\src\Driver\PDO\Result.php:107
.\vendor\doctrine\dbal\src\Driver\PDO\Result.php:38
.\vendor\doctrine\dbal\src\Result.php:59

What am I missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You try to execute DDL query like it would be a DML SELECT. There will be no result set as an outcome of such operation

assuming that $em is EntityManager do this

$em->getConnection()->executeQuery($yourQuery);

no ResultSetMapping nor other stuff anywhere.

Please be advised that this is not something I have tested myself nor I am active user of the Doctrine. I am convinced as for the cause, not if the snippet is a valid (googled it out)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading