General developer forum

 
 
Picture of stephane ng
post beginner API Moodle 2
 

 

Hi all,

I have my owned script LDAP,

and I whant enrol members student and teacher automatical with LDAP.

I want create in folder moodle/myScript form only my work coding.

How i can't call $DB ?

is enought to use $DB ? or if not correcty for keep $db how i mus do

//moodle/myScript

include '../config.php'; //use $DB whith filder config.php

var_dump($db);

thank's for reply me

 

 

 
Average of ratings: -
Rajesh Taneja
Re: post beginner API Moodle 2
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Testers

Stephane your script seems to be on same level as config.php (moodle/myScript), and include refers to parent directory.

Also, try using require_once to make sure config.php is loaded. $DB (all caps), is global variable and if you are using this in function then don't forget to use global $DB;

Hope this helps.

 
Average of ratings: -
Picture of stephane ng
Re: post beginner API Moodle 2
 

thank for reply smile

is it correctely for use $DB and $CFG

my folder moodle config.php

/var/www/mdl/config.php

 

my folder my script LDAP is

/var/www/mdl/LDAP/my_script.php

I try this

<?php
require_once('/var/www/mdl/config.php');
echo "<h1>TO USE DB</h1>";
var_dump($DB);
echo "<h1> TO USE CFG</h1>";
var_dump($CFG);

?>

 

my script is ok , i have this display

 

TO USE DB

object(mysqli_native_moodle_database)#5 (27) { ["mysqli":protected]=> object(mysqli)#6 (18) { ["affected_rows"]=> int(1) ["client_info"]=> string(6) "5.5.24" ["client_version"]=> int(50524) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(9) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(27) "5.5.24-0ubuntu0.12.04.1-log" ["server_version"]=> int(50524) ["stat"]=> string(140) "Uptime: 7245 Threads: 1 Questions: 112959 Slow queries: 0 Opens: 3386 Flush tables: 1 Open tables: 400 Queries per second avg: 15.591" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(616) ["warning_count"]=> int(0) } ["transactions_supported":"mysqli_native_moodle_database":private]=> NULL ["database_manager":protected]=> NULL ["temptables":protected]=> object(mysqli_native_moodle_temptables)#7 (3) { ["mdb":protected]=> *RECURSION* ["prefix":protected]=> string(5) "prod_" ["temptables":protected]=> array(0) { } } ["tables":protected]=> NULL ["dbhost":protected]=> string(9) "localhost" ["dbuser":protected]=> string(4) "root" ["dbpass":protected]=> string(4) "test" ["dbname":protected]=> string(11) "moodle_prod" ["prefix":protected]=> string(5) "prod_" ["dboptions":protected]=> array(2) { ["dbpersist"]=> int(0) ["dbsocket"]=> int(0) } ["external":protected]=> bool(false) ["reads":protected]=> int(8) ["writes":protected]=> int(0) ["debug":protected]=> int(0) ["last_sql":protected]=> NULL ["last_params":protected]=> NULL ["last_type":protected]=> int(1) ["last_extrainfo":protected]=> NULL ["last_time":protected]=> float(1372169887.6973) ["loggingquery":"moodle_database":private]=> bool(false) ["used_for_db_sessions":protected]=> bool(true) ["transactions":"moodle_database":private]=> array(0) { } ["force_rollback":"moodle_database":private]=> bool(false) ["settingshash":"moodle_database":private]=> NULL ["fix_sql_params_i":"moodle_database":private]=> NULL ["inorequaluniqueindex":"moodle_database":private]=> int(1) }

TO USE CFG

object(stdClass)#1 (526) { ["dbtype"]=> string(6) "mysqli" ["dblibrary"]=> string(6) "native" ["dbhost"]=> string(9) "localhost" ["dbname"]=> string(11) "moodle_prod" ["dbuser"]=> string(4) "root" ["dbpass"]=> string(4) "test" ["prefix"]=> string(5) "prod_" ["dboptions"]=> array(2) { ["dbpersist"]=> int(0) ["dbsocket"]=> int(0) } ["wwwroot"]=> string(21) "http://localhost/prod" ["dataroot"]=> string(15) "/var/moodledata" ["admin"]=> string(5) "admin" ["directorypermissions"]=> int(511) ["passwordsaltmain"]=> string(27) "SNd6T=;OTf#-h^/G=k

 

And now , is have a simple method for call DB and CFG ?,

I think a autoloder, is moodle2 have a autoloader for caller simple ?

Or my method is simple correctely for the next programming with moodle2.

 

 

 

 

 

 
Average of ratings: -