Hi there,
I’m using dhtmlxScheduler with a PHP application which makes use of a modified ADODB database abstraction layer. Now I don’t want to limit my application to only mysql by using something like
$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db);
To use my application with dhtmlxScheduler on different databases I have to replace all the mysql functions.
In my example below I am able to do to make (theoretically) INSERT and UPDATE calls to any database by connecting to the DB by using Global $CFG variable and my application’s own database manipulation functions (e.g. execute_sql).
That code would work on MS SQL, MySQL, Postgres, SQLLite and Oracle without changing anything if only for the mysql_connect mysql_select parts.
<?php require_once('../../config.php'); include ('config.php'); include ('codebase/scheduler_connector.php'); $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); $scheduler = new schedulerConnector($res); $scheduler->enable_log("log.txt",true); function myUpdate($action) { Global $CFG; $start = strtotime($action->get_value('sessdate')); $finish = strtotime($action->get_value('sessionend')); $duration = ($finish - $start); $description = $action->get_value('description'); $subject = $action->get_value('subject'); $teacher = $action->get_value('teacher'); $sessiontitle = $action->get_value('sessiontitle'); $courseid = $action->get_value('courseid'); execute_sql("UPDATE {$CFG->prefix}attendance_sessions SET courseid = '{$courseid}', sessdate = '{$start}', duration = '{$duration}', sessionend = '{$finish}', description = '{$action->get_value('description')}', teacher = '{$action->get_value('teacher')}', subject = '{$action->get_value('subject')}', sessiontitle = '{$action->get_value('sessiontitle')}' WHERE id='{$action->get_id()}'"); $action->success(); } function myInsert($action) { Global $CFG; $start = strtotime($action->get_value('sessdate')); $finish = strtotime($action->get_value('sessionend')); $duration = ($finish - $start); $description = $action->get_value('description'); $subject = $action->get_value('subject'); $teacher = $action->get_value('teacher'); $sessiontitle = $action->get_value('sessiontitle'); $courseid = $action->get_value('courseid'); execute_sql("INSERT INTO {$CFG->prefix}attendance_sessions (courseid, sessdate, duration, sessionend,description, teacher, subject, sessiontitle) VALUES ('{$courseid}', '{$start}', '{$duration}', '{$finish}', '{$description}', '{$teacher}', '{$subject}', '{$sessiontitle}')"); $action->success(); } $scheduler->event->attach("beforeUpdate","myUpdate"); $scheduler->event->attach("beforeInsert","myInsert"); $scheduler->render_sql("SELECT s.id,from_unixtime(s.sessdate) AS sessdate,from_unixtime(s.sessionend) AS sessionend,s.description,su.subject,t.teacher,s.sessiontitle,c.shortname as courseid FROM {$CFG->prefix}attendance_sessions s LEFT JOIN {$CFG->prefix}course c ON s.courseid = c.id LEFT JOIN {$CFG->prefix}groups g ON s.groupid = g.id LEFT JOIN {$CFG->prefix}attendance_teachers t ON s.teacher = t.id LEFT JOIN {$CFG->prefix}attendance_subjects su ON s.subject = su.id","id","sessdate,sessionend,description,subject,teacher,sessiontitle,courseid"); ?>Please, how can I get rid of the mysql specific code?
Here is how my database config.php file works:
<?php unset ( $CFG ) ; $CFG->dbtype = 'mysql' ; $CFG->dbhost = 'localhost' ; $CFG->dbname = 'dbname' ; $CFG->dbuser = 'username' ; $CFG->dbpass = 'secret'; $CFG->dbpersist = false; $CFG->prefix = 'tbl_'; $CFG->wwwroot = 'http://www.example.com' ; $CFG->dirroot = '/home/admin/public_html/example.com' ; $CFG->dataroot = '/home/admin/public_html/example.com/uploaddata' ; $CFG->admin = 'admin' ; $CFG->directorypermissions = 00777 ; $CFG->unicodedb = true ; require_once ( "$CFG->dirroot/lib/setup.php" ) ; ?>Thanks a lot,
Barry