I want to execute a query in raw SQL with Doctrine. I have an error but I don't know where.
$my_id = 12;
$pdo = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$q = 'SELECT date FROM my_table WHERE my_text LIKE "%'.$my_id.'%" ORDER BY date DESC LIMIT 1';
$r = $pdo->query($q)->fetch开发者_如何学编程One();
$result['date'] = $r->date;
The error is $pdo->fetchOne();
: "Call to undefined method PDO::fetchOne()"
I have the same message with fetchAll().
How can it be fixed?
Answer as written in comments:
Here is the correct code :
$conn = Doctrine_Manager::getInstance()->getCurrentConnection(); $q = 'SELECT date FROM my_table WHERE ...'; $r = $conn->fetchAssoc($q); echo $r[0]['date'];
精彩评论