在 codeigniter 中,您可以使用Active Records
来执行此操作,也可以通过传递您的自定义查询,例如
$username="test";
$password="password";
$query="SELECT dd.deptname,sd.studentname FROM dept_details dd
INNER JOIN login_details ld ON (dd.deptcode = ld.deptcode)
INNER JOIN student_details sd ON (ld.deptcode = sd.deptcode)
WHERE ld.username='".$username."' AND ld.password='".$password."' ";
$result=$this->db->query($query)->result();
或者
$this->db->select('dd.deptname,sd.studentname');
$this->db->from('dept_details dd');
$this->db->join('login_details ld', 'dd.deptcode = ld.deptcode');
$this->db->join('student_details sd', 'd.deptcode = sd.deptcode');
$this->db->where('ld.username', $username);
$this->db->where('ld.password', $password);
$result = $this->db->get();
并确保您已将database
库加载到autoload.php
类似
$autoload['libraries'] = array("database");
这是Active Record的帮助
希望它有意义