2012-09-21 85 views
0

我想在CakePHP的2.0 MySQL查詢看起來像這樣:Mysql的CakePHP的2.0

select p.ciname HOSTNAME 
    ,a.status HPSA 
    ,m.status SM9 
    ,p.status LDAP 
from hpsas a, hpsms m, ldaps p 
where (p.ciname = a.ciname) 
and (p.ciname = m.ciname) 
order by p.ciname; 

這可能嗎?

+0

模型的名稱是什麼? –

+0

該模型如下所示:<?php class Test extends AppModel public $ useTable ='ldaps'; } – DenVer

回答

0

您可以使用Model.query()方法在CakePHP中進行任意SQL查詢。例如,在一個控制器:

$sql = ...your sql here... 
$results = $this->ModelName->query($sql); 
0

,如果你想使用的蛋糕ORM我認爲這將是朝這個方向邁出的一步,使這個查詢:

$options = array(); 
$options['fields'] => array('p.ciname AS HOSTNAME', 'a.status AS HPSA', 'm.status AS SM9', 'p.status AS LDAP'); 
$options['joins'][] => array('table' => 'hpsas', 'alias' => 'a', 'conditions' => array('p.ciname = a.ciname')); 
$options['joins'][] => array('table' => 'hpsms', 'alias' => 'm', 'conditions' => array('p.ciname = m.ciname')); 

$result = $this->Test->find('all', $options); 

這些字段和表名唐」不符合蛋糕慣例,如果你正在遷移或整合你的項目,這是可以理解的。如果你現在開始,你可能想重新命名它們。

http://book.cakephp.org/1.3/en/view/901/CakePHP-Conventions