phalcon框架中如何实现脱离模型进行sql查询?
比如,我有表A和表B,在models/下有A.php这个model类,而没有B的,现在在A中需要对表B进行一次SQL查询,在不创建B的model类的情况下如何拿到B的数据? PHP 框架
[解决办法]
$ar = $obj->fetchAll($sql);
或
$r = $obj->fetchOne($sql);
其实 Phalcon 的类都是可以单独使用的,并不一定非要在框架中使用
比如
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(Array
"host" => "localhost",
"username" => "root",
"password" => "",
"dbname" => "test"
));
//print_r(get_class_methods($connection)); //从支持的方法上看,只不过是在PDO上扩展了一些功能
$connection->query('set names gbk');
$t = $connection->fetchAll('select * from `123`', 1);
print_r($t);
[时间] => 2013-06-05 08:48:00
)
[2] => Array
(
[id] => 3
[姓名] => 王五
[型号] => A1-200
[工位] => C
[数量] => 45
[时间] => 2013-06-05 07:48:00
)
[3] => Array
(
[id] => 4
[姓名] => 张三
[型号] => A8-300
[工位] => A
[数量] => 420
[时间] => 2013-06-05 10:46:00
)
[4] => Array
(
[id] => 5
[姓名] => 王五
[型号] => A8-300
[工位] => C
[数量] => 500
[时间] => 2013-06-05 13:46:00
)
)
我这个表很怪异吧