开发者

Raw SQL with Doctrine

开发者 https://www.devze.com 2023-04-10 07:39 出处:网络
I want to execute a query in raw SQL with Doctrine. I have an error but I don\'t know where. $my_id = 12;

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

精彩评论

暂无评论...
验证码 换一张
取 消