我们都知道我们不能连接来自不同数据库的表
不确定是否适用于您的情况,但这里有一些关于跨数据库查询的帖子:
一次查询多个数据库
PHP Mysql 跨数据库连接
https://stackoverflow.com/a/5698396/183254
无论如何,您不需要使用联接;只需查询其他数据库以查看该事物是否处于活动状态
$DB2 = $this->load->database('otherdb', TRUE);
$active = $DB2->query('SELECT is_active blah...');
if($active)
{
//do other query
}
更新
这可能在语法上不正确,但应该为您指明正确的方向。一如既往,用户指南。
// load other db
$db2 = $this->load->db('otherdb',TRUE);
// get enrolled student id's from other db
$active_students = $db2->query('SELECT id FROM students WHERE enrolled = 1')->result();
// query this db for what you want
$this->db->select('count(IDNO), course, sum(student_balance)');
$this->db->where('school_term',2013);
$this->db->where('student_balance >',0);
// where_in will limit the query to the id's in $active_students
$this->db->where_in('id', $active_students);
// finally, execute the query on the student_balances table
$balances = $this->db->get('student_balances');