General developer forum

Using DB functions for Oracle

 
Picture of Jack Eapen
Using DB functions for Oracle
 

Hi,

I've a Moodle instance with MySQL. I'm writing a small tool to connect to an Oracle database and fetch data from some tables- basically some reports. How can I use Moodle's excellent database functions (like get_records, get_records_select) in my code? Which all files need to be included? How to create another connection to Oracle (as my original config.php connection is to MySQL).

 
Average of ratings: -
Picture of Mark Johnson
Re: Using DB functions for Oracle
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

You should be able to include lib/dml/oci_native_moodle_database.php and create a new instance of the oci_native_moodle_database class. Pass true to the $external parameter in the constructor, then call connect() with your database credentials.

 
Average of ratings: Useful (1)
Picture of Jack Eapen
Re: Using DB functions for Oracle
 

thanks. In fact, I'm very new to PHP. Learning things only. what i tried is as below: (my file is at root of moodle folder)


require(__DIR__ . '/lib/dml/oci_native_moodle_database.php');

$OCI= new oci_native_moodle_database(true);

$oracle_connection= $OCI->connect('myserver', 'user', 'pass', 'oracle SID', '')) {

$students = $OCI->get_records_sql("SELECT * from students") ;

                                         echo '<pre>';

                                          print_r($students);

                                          echo '</pre>';


I'm not getting any display, or error. what corrections should I make? I have oci extension for PHP as i can see from my phpinfo()

 
Average of ratings: -
Picture of Neill Magill
Re: Using DB functions for Oracle
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

For a good example of how it has been done in Moodle look at the logstore_database plugin

 
Average of ratings: -