How to use Doctrine2 type conversion for native COLUMNS queries

Could not find anything on this - it seems that it should be direct, though.

So, an example of Doctrine2 docs for type conversion by related parameters is as follows:

$date = new \DateTime("2011-03-05 14:00:21"); $stmt = $conn->prepare("SELECT * FROM articles WHERE publish_date > ?"); $stmt->bindValue(1, $date, "datetime"); $stmt->execute(); 

What I want to do is specify a type conversion for one of the columns, but nothing was found in the documents or in StackOverflow. A pseudo-example of how this might look:

 $stmt = $conn -> prepare("SELECT datetime FROM articles WHERE id = 1"); $stmt -> setType(0, "date_type"); // 0 being the column position, "date_type" being the PHP type to convert to 

If anyone knows how to do this (this is SQL not DQL), I would really appreciate it. Thanks.

+4
source share
1 answer

This is not something that works at the DBAL level. If you use NativeSQL queries in ORM, you can get this conversion through hydration (see Section

+5
source

All Articles