gpt4 book ai didi

php - 在 Yii 中返回 CActiveDataProvider

转载 作者:行者123 更新时间:2023-11-30 23:02:49 24 4
gpt4 key购买 nike

我有 4 个数据库表:

用户:id、用户名、密码

楼层:id, userid, name

房间:id,楼层,名字

学生:id, room, name, active

如何为后续的 SQL 命令返回 CActiveDataProvider?

SELECT * FROM `student` WHERE `student`.`active` = 0 AND `student`.`room` IN (SELECT `room`.`id` FROM `room` WHERE `room`.`floor` = (SELECT `floor`.`id` FROM `floor` WHERE `floor`.`userid` = $userid))

我试过:

$model = Student::model()->findAllBySql("SELECT * FROM student WHERE active = 0 AND room IN (SELECT id FROM room WHERE floor = (SELECT id FROM floor WHERE user = $user))");
return new CActiveDataProvider($model);

但是响应:

Fatal error: Call to a member function getDbCriteria() on a non-object in X:appserv\www\framework\web\CActiveDataProvider.php on line 225

最佳答案

命名占位符很有用。

$criteria = new CDbCriteria;
$criteria->condition = 'student.active = 0 AND student.room IN (SELECT room.id FROM room WHERE room.floor = (SELECT floor.id FROM floor WHERE floor.userid = :userid))';
$criteria->params=array(':userid'=>$userid);
$dataProvider = new CActiveDataProvider('Student',array('criteria'=>$criteria,));

关于php - 在 Yii 中返回 CActiveDataProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23239758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com