Cake 2.X retrive data from rawQuery

2019-07-17 23:44发布

问题:

As show at CakePHP 2.1.x - Run a query without any models in AppController I have a query,

 $q = "select id from table where id=123";
 $db = ConnectionManager::getDataSource('default');
 $qr = $db->rawQuery($q);

ok (!), it works... But, how to get my data?? Where the tutorial examples?

I need something like $data = $qr->fetchAll() method or $id = getMyData($qr) function.

回答1:

I believe this may be the solution or at least a point in the right direction.

$q = "select id from table where id=123";
$db = ConnectionManager::getDataSource('default');
$myData = $db->query($q);


标签: cakephp-2.0