Moodle: 查询任意数据库

代码:

if (!file_exists('../../config.php')) {
    header('Location: ../../install.php');
    die;
} 

require_once('../../config.php');
require_once("../../mod/feedback/lib.php");
    
// 课程ID    
$course_id = 22; //课程ID

/*
$sql = "select 
                m.id as m_id, 
                m.name as m_name, 
                cm.id as cm_id,
                cm.course as cm_course,
                cm.module as cm_module,
                cm.instance as cm_instance,
                cm.instance as cm_instance,
                cm.section as cm_section
                
                
        from {modules} m, {course_modules} cm where cm.module=m.id and cm.course = '$course_id' and cm.id in (SELECT cs.sequence FROM {course_sections} cs where cs.course = '$course_id')";
*/

// 显示所有tables
//$sql = "SHOW TABLES"; 

// 显示某一表的所有字段
//$sql = "SHOW COLUMNS FROM {quiz_feedback}";

// 自定义查询
$sql = "select * FROM {course_modules} cm where cm.course = '$course_id' and cm.module=7";  

//$sql = "select cm.*, m.* from {modules} m, {course_modules} cm where cm.module=m.id and cm.course = '$course_id' and cm.id in (SELECT cs.sequence FROM {course_sections} cs where cs.course = '$course_id')";
$res = $DB->get_records_sql($sql);
 

echo '<pre>';  echo '$cm===>'; print_r($res);  echo '</pre>'; die;

 

原文:Moodle: 查询任意数据库