简体   繁体   English

从moodle数据库中获取数据

[英]Fetching data from moodle database

I am trying to query some data from the moodle database. 我试图从moodle数据库查询一些数据。 I am using the data manipulation API. 我正在使用数据操作API。 Here is my code. 这是我的代码。 When I run it on the browser, i get a blank screen. 当我在浏览器上运行它时,我得到一个空白屏幕。 i reall dont know what the $enrolids is. 我真的不知道$ enrolids是什么。 Is it an associative array or what. 它是一个关联数组还是什么。 Even when I try create an associative array, I still get a blank screen. 即使我尝试创建一个关联数组,我仍然会得到一个空白屏幕。

<?php
require_once("../config.php");
$userid=$_GET['userid'];
//Get the enrolids from the mdl_user_enrolments table
$enrolids=$DB->get_records_sql('SELECT enrolid FROM {user_enrolments} WHERE userid=?', array($userid));
echo $enrolids['enrolid'];
?>

Will appreciate the help.... 将欣赏帮助....

I figured it out: To anyone with the same problem. 我想出来了:对于有同样问题的人。 Here is the solution. 这是解决方案。 Moodle is object oriented. Moodle是面向对象的。 Meaning, the queries made, return an Array of stdclass objects ie: 意思是,所做的查询返回一个stdclass对象数组,即:

Array ( [1] => stdClass Object ( [id] => 1 [status] => 0 [enrolid] => 5 [userid] => 3 [timestart] => 0 [timeend] => 2147483647 [modifierid] => 0 [timecreated] => 0 [timemodified] => 0 ) [2] => stdClass Object ( [id] => 2 [status] => 0 [enrolid] => 6 [userid] => 3 [timestart] => 0 [timeend] => 2147483647 [modifierid] => 0 [timecreated] => 0 [timemodified] => 0 ) ) 

Use the -> notation to fetch whatever value you desire ie If the above array is stored in a variable eg $arr, do the following to access status for example 使用 - >表示法获取您想要的任何值,即如果上述数组存储在变量中,例如$ arr,请执行以下操作以访问状态,例如

$arr[1]->status;

CHEERS.... 干杯....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM