General developer forum

 
 
Picture of nikhil pednekar
get_records_sql
 

hi,

I am trying with sql query to show my result...but when i run my page it shows.

I am trying on local server. using wamp.

ERROR READING FROM DATABASE...

May be get_records_sql function doesn't supporting.

here is my sql query...

$sql_check_course = "
SELECT c.id AS id, c.fullname, u.username, u.firstname, u.lastname, u.email
FROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt, mdl_role r
WHERE ra.userid=u.id AND ra.contextid=cxt.id AND cxt.contextlevel=50
AND cxt.instanceid=c.id AND c.id = 4 AND r.shortname = 'student';
";

$result_check_user = $DB->get_records_sql($sql_check_course,$params,50,0);

..

...

 

Does anyone knows any possible solution...please revert back

regards,

Nikhil Pednekar

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: get_records_sql
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

What is the rest of the error message after "Error reading from database"? That will tell you what the problem is. (You have got Debugging set to DEVELOPER level, right?)

 
Average of ratings: -
Picture of nikhil pednekar
Re: get_records_sql
 

Hi Tim,

I set debugging to developer...thanks for suggesting...now they are showning the debug info

Below is error which they are showing

Debug info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 50, 18446744073709551615' at line 5

SELECT c.id AS id, c.fullname, u.username, u.firstname, u.lastname, u.email
FROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt, mdl_role r
WHERE ra.userid=u.id AND ra.contextid=cxt.id AND cxt.contextlevel=50
AND cxt.instanceid=c.id AND c.id = 4 AND r.shortname = 'student';
LIMIT 50, 18446744073709551615
[array (
)]
Error code: dmlreadexception
Stack trace:
  • line 407 of \lib\dml\moodle_database.php: dml_read_exception thrown
  • line 966 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 171 of \my\reports_ajax.php: call to mysqli_native_moodle_database->get_records_sql()

 

Please help me to solve this...

Thanks.

 
Average of ratings: -
Davo
Re: get_records_sql
Group DevelopersGroup Particularly helpful Moodlers

The error message tells you exactly where to look - error near (actually, it means 'just before') 'LIMIT 50 ...'

If you look on the line before that - you have got an extra ';' which shouldn't be there.

 
Average of ratings:Useful (3)
Picture of nikhil pednekar
Re: get_records_sql
 

Hey,

It solved my problem.......

Thanks a lot Davo, Tim...

 

Thanks again

 

 
Average of ratings: -
Picture of Hubert Chathi
Re: get_records_sql
 

Aside from the semicolon that made your query fail, you also should not be hard-coding the "mdl_" table prefix; you should wrap your table names in braces.  So, instead of, for example, "mdl_role_assignments", write "{role_assignments}".

 
Average of ratings:Useful (2)