关于在CONTROLLER里面执行SQL的问题 [ 新手入门 ]
public function getMysqlVersion() {
$db = Yii::app()->db; //you have to define db connection in config/main.php
$sql = "select version()";
$command = $db->createCommand($sql);
$results = $command->queryAll();
foreach($results as $result){
print_r($result);
}
}
出现错误,
PHP Error
Undefined variable: results
E:\webTools\htdocs\openShop\public\protected\controllers\AdminController.php(91)
79 {
80 Yii::app()->user->logout();
81 $this->redirect(Yii::app()->homeUrl);
82 }
83 /**
84 85 */
86 public function getMysqlVersion() {
87 $db = Yii::app()->db; //you have to define db connection in config/main.php
88 $sql = "select version()";
89 $command = $db->createCommand($sql);
90 91 foreach($results as $result){
92 print_r($result);
93 }
94
95 }
96 }
错误页上没有91行,程序中是有的,就是
$results = $command->queryAll();这个。
请问,大家可以告诉我原因吗?
共 2 条回复
-
lz19881123 回复于 2011-08-06 21:54 举报
大哥,不会吧,应该是在model里吧!
-
instnet
注册时间:2011-08-04
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱35
- 威望0
- 积分35