没有原始 SQL 查询的 Moodle 连接表
Moodle join tables without raw SQL query
我是 Moodle 世界的新手。我想使用 PDO 内部连接 2 个或更多表。我检查了 documentation 但找不到任何有用的信息。也许我遗漏了 Moodle 的某些部分。假设我想让所有用户注册到指定的课程。
有什么办法可以制作类似这样的东西吗:
$users = get_records(['course', 'user'], 'course.id = user.course_id');
我收到了 Moodle forum 的回复:
No.
The DB API is there to simplify many common situations (e.g. getting
one or more records from a single table), but if you need to gather
data from more than one table at once, then you need to use
$DB->get_records_sql()
(or similar).
However, if you want a list of users in a particular course, then use
the get_enrolled_users()
function, rather than trying to manually
write the SQL query for it.
我是 Moodle 世界的新手。我想使用 PDO 内部连接 2 个或更多表。我检查了 documentation 但找不到任何有用的信息。也许我遗漏了 Moodle 的某些部分。假设我想让所有用户注册到指定的课程。 有什么办法可以制作类似这样的东西吗:
$users = get_records(['course', 'user'], 'course.id = user.course_id');
我收到了 Moodle forum 的回复:
No.
The DB API is there to simplify many common situations (e.g. getting one or more records from a single table), but if you need to gather data from more than one table at once, then you need to use
$DB->get_records_sql()
(or similar).However, if you want a list of users in a particular course, then use the
get_enrolled_users()
function, rather than trying to manually write the SQL query for it.