Use $DB to query neighbor database on same server/connection

Re: Use $DB to query neighbor database on same server/connection

لە لایەن Mark Johnson -
Number of replies: 1
وێنەی Core developers وێنەی Particularly helpful Moodlers وێنەی Peer reviewers وێنەی Plugin developers

Don't mess with the $DB global (you will break things), but you can create an instance of the moodle_database class (or an appropriate subclass like mysqli_native_moodle_database) and use that to query other databases. 

Perhaps something like this:

$extdb = new mysql_native_moodle_database(true); // true says that it's an external database, so don't use Moodle's prefix
$extdb->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, 'neighbor', '');


تێکرایى نمرەپێدراوەکان:Useful (3)
In reply to Mark Johnson

Re: Use $DB to query neighbor database on same server/connection

لە لایەن Frank Troglauer -

Hey Mark,

Thanks for the swift reply. This suggestion works splendidly. The only thing I had to change was on the first line of the sample code I added i to the mysql_native_moodle_database so it is instead mysqli_native_moodle_database. 


Thanks!