Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine2 native query update statement

How to do a native sql query in Doctrine 2, executing an update statement? The createNativeQuery method on EntityManager, requires a second parameter (ResultSetMapping) to be able to map the resultsets to Objects.

But when updating (or inserting, or set, or...) there is no resulset to map. Passing null or just new ResultSetMapping(), gives an error.

Are only select queries supported for native sql?

like image 664
Sewdn Avatar asked Dec 07 '22 20:12

Sewdn


1 Answers

Essentially ditto w/ faken,

this from the docs:

If you want to execute DELETE, UPDATE or INSERT statements the Native SQL API cannot be used and will probably throw errors. Use EntityManager#getConnection() to access the native database connection and call the executeUpdate() method for these queries.

one note of use is the connection object can be retrieved from the EntityManager:

$conn = $entityManager->getConnection();
$rowsAffected = $conn->executeUpdate($sql, $params, $types);
like image 151
quickshiftin Avatar answered Dec 10 '22 13:12

quickshiftin