Can't use Data manipulation API

Can't use Data manipulation API

by D K -
Number of replies: 2

Hello. I can't understand what I do wrong.
I've created file "test.php" in moodle/testfolder:

<?php
// require_once(dirname(__FILE__).'/config.php';

function my_function() {
      global $DB;
      $record = $DB->get_record('user', array('id' => 2));
      var_dump($record);
}

my_function();
?>

But when I open http://localhost/testfolder/test.php nothing happend. HTTP ERROR 500.
I've tried with require_once or without - same.

Please help.

Average of ratings: -
In reply to D K

Re: Can't use Data manipulation API

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Because the require for config.php is commented out? You definitely need to include config.php.

What caused the error 500? The full story should be in your web server's error log. 

In reply to D K

Re: Can't use Data manipulation API

by Olumuyiwa Taiwo -
Picture of Plugin developers

  • You're missing a closing bracket on the first line.
  • Uncomment the first line

I'll suggest using a code editor or IDE that helps with spotting basic problems.

Average of ratings: Useful (1)