Max
Max

Reputation: 1

Raw SQL with Doctrine

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)->fetchOne(); 
$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?

Upvotes: 0

Views: 2109

Answers (1)

Sathyajith Bhat
Sathyajith Bhat

Reputation: 21851

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'];

Upvotes: 1

Related Questions