Reputation: 479
I am trying out sample queries of the Data Manipulation API for moodle. I have tried out the following query so far
<?php
require './config.php';
global $DB;
$user= $DB->get_record_sql('SELECT * FROM {mdl_user} WHERE id=?', array(1));
echo mysql_num_rows($user);
?>
I am getting 'Error Reading from Database'. I am using moodle on a local installation. What am I doing wrong here?
Upvotes: 1
Views: 2175
Reputation: 5943
get_records_sql()
return the records as an array of objects. In this case you're getting just one record, so it is a single object.
With the appropriate corrections, this code worked for me:
<?php
require './config.php';
global $DB;
$user= $DB->get_record_sql('SELECT * FROM {user} WHERE id=?', array(1));
var_dump($user);
?>
Upvotes: 2