当前位置: 首页>>代码示例>>PHP>>正文


PHP moodle_database类代码示例

本文整理汇总了PHP中moodle_database的典型用法代码示例。如果您正苦于以下问题:PHP moodle_database类的具体用法?PHP moodle_database怎么用?PHP moodle_database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了moodle_database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Object constructor.
  *
  * @param moodle_database $mdb Connection to the target database (a
  * @see moodle_database object). Use null to use the current $DB connection.
  * @param boolean $check_schema - whether or not to check that XML database
  * schema matches the RDBMS database schema before importing (inside
  * @see begin_database_import).
  */
 public function __construct(moodle_database $mdb, $check_schema = true)
 {
     $this->mdb = $mdb;
     $this->manager = $mdb->get_manager();
     $this->schema = $this->manager->get_install_xml_schema();
     $this->check_schema = $check_schema;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:database_importer.php

示例2: test_concurrent_temp_tables

 public function test_concurrent_temp_tables()
 {
     $DB = $this->tdb;
     // do not use global $DB!
     $dbman = $this->tdb->get_manager();
     // Define 2 records
     $record1 = (object) array('course' => 1, 'secondname' => '11 important', 'intro' => '111 important');
     $record2 = (object) array('course' => 2, 'secondname' => '22 important', 'intro' => '222 important');
     // Create temp table1 and insert 1 record (in DB)
     $table = $this->tables['test_table1'];
     $dbman->create_temp_table($table);
     $this->assertTrue($dbman->table_exists('test_table1'));
     $inserted = $DB->insert_record('test_table1', $record1);
     // Switch to new connection
     $cfg = $DB->export_dbconfig();
     if (!isset($cfg->dboptions)) {
         $cfg->dboptions = array();
     }
     $DB2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
     $DB2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions);
     $dbman2 = $DB2->get_manager();
     $this->assertFalse($dbman2->table_exists('test_table1'));
     // Temp table not exists in DB2
     // Create temp table1 and insert 1 record (in DB2)
     $table = $this->tables['test_table1'];
     $dbman2->create_temp_table($table);
     $this->assertTrue($dbman2->table_exists('test_table1'));
     $inserted = $DB2->insert_record('test_table1', $record2);
     $dbman2->drop_temp_table($table);
     // Drop temp table before closing DB2
     $this->assertFalse($dbman2->table_exists('test_table1'));
     $DB2->dispose();
     // Close DB2
     $this->assertTrue($dbman->table_exists('test_table1'));
     // Check table continues existing for DB
     $dbman->drop_temp_table($table);
     // Drop temp table
     $this->assertFalse($dbman->table_exists('test_table1'));
 }
开发者ID:nickread,项目名称:moodle,代码行数:39,代码来源:testddl.php

示例3: test_concurent_transactions

 function test_concurent_transactions()
 {
     // Notes about this test:
     // 1- MySQL needs to use one engine with transactions support (InnoDB).
     // 2- MSSQL needs to have enabled versioning for read committed
     //    transactions (ALTER DATABASE xxx SET READ_COMMITTED_SNAPSHOT ON)
     $DB = $this->tdb;
     $dbman = $DB->get_manager();
     $table = $this->get_test_table();
     $tablename = $table->getName();
     $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
     $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
     $dbman->create_table($table);
     $transaction = $DB->start_delegated_transaction();
     $data = (object) array('course' => 1);
     $this->assertEqual(0, $DB->count_records($tablename));
     $DB->insert_record($tablename, $data);
     $this->assertEqual(1, $DB->count_records($tablename));
     //open second connection
     $cfg = $DB->export_dbconfig();
     if (!isset($cfg->dboptions)) {
         $cfg->dboptions = array();
     }
     $DB2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
     $DB2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions);
     // second instance should not see pending inserts
     $this->assertEqual(0, $DB2->count_records($tablename));
     $data = (object) array('course' => 2);
     $DB2->insert_record($tablename, $data);
     $this->assertEqual(1, $DB2->count_records($tablename));
     // first should see the changes done from second
     $this->assertEqual(2, $DB->count_records($tablename));
     // now commit and we should see it finally in second connections
     $transaction->allow_commit();
     $this->assertEqual(2, $DB2->count_records($tablename));
     $DB2->dispose();
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:38,代码来源:testdml.php

示例4: spl_autoload_register

} else {
    spl_autoload_register('core_component::classloader');
}
require $CFG->dirroot . '/version.php';
$CFG->target_release = $release;
\core\session\manager::init_empty_session();
global $SESSION;
global $USER;
global $COURSE;
$COURSE = new stdClass();
$COURSE->id = 1;
global $SITE;
$SITE = $COURSE;
define('SITEID', 1);
//Database types
$databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'), 'mariadb' => moodle_database::get_driver_instance('mariadb', 'native'), 'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'), 'oci' => moodle_database::get_driver_instance('oci', 'native'), 'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), 'mssql' => moodle_database::get_driver_instance('mssql', 'native'));
foreach ($databases as $type => $database) {
    if ($database->driver_installed() !== true) {
        unset($databases[$type]);
    }
}
if (empty($databases)) {
    $defaultdb = '';
} else {
    reset($databases);
    $defaultdb = key($databases);
}
// now get cli options
list($options, $unrecognized) = cli_get_params(array('chmod' => isset($distro->directorypermissions) ? sprintf('%04o', $distro->directorypermissions) : '2777', 'lang' => $CFG->lang, 'wwwroot' => '', 'dataroot' => empty($distro->dataroot) ? str_replace('\\', '/', dirname(dirname(dirname(dirname(__FILE__)))) . '/moodledata') : $distro->dataroot, 'dbtype' => empty($distro->dbtype) ? $defaultdb : $distro->dbtype, 'dbhost' => empty($distro->dbhost) ? 'localhost' : $distro->dbhost, 'dbname' => 'moodle', 'dbuser' => empty($distro->dbuser) ? 'root' : $distro->dbuser, 'dbpass' => '', 'dbport' => '', 'dbsocket' => '', 'prefix' => 'mdl_', 'fullname' => '', 'shortname' => '', 'summary' => '', 'adminuser' => 'admin', 'adminpass' => '', 'adminemail' => '', 'non-interactive' => false, 'agree-license' => false, 'allow-unstable' => false, 'help' => false), array('h' => 'help'));
$interactive = empty($options['non-interactive']);
// set up language
开发者ID:mongo0se,项目名称:moodle,代码行数:31,代码来源:install.php

示例5: test_session_locks

 public function test_session_locks()
 {
     $DB = $this->tdb;
     $dbman = $DB->get_manager();
     // Open second connection.
     $cfg = $DB->export_dbconfig();
     if (!isset($cfg->dboptions)) {
         $cfg->dboptions = array();
     }
     $DB2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
     $DB2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions);
     // Testing that acquiring a lock effectively locks.
     // Get a session lock on connection1.
     $rowid = rand(100, 200);
     $timeout = 1;
     $DB->get_session_lock($rowid, $timeout);
     // Try to get the same session lock on connection2.
     try {
         $DB2->get_session_lock($rowid, $timeout);
         $DB2->release_session_lock($rowid);
         // Should not be executed, but here for safety.
         $this->fail('An Exception is missing, expected due to session lock acquired.');
     } catch (moodle_exception $e) {
         $this->assertInstanceOf('dml_sessionwait_exception', $e);
         $DB->release_session_lock($rowid);
         // Release lock on connection1.
     }
     // Testing that releasing a lock effectively frees.
     // Get a session lock on connection1.
     $rowid = rand(100, 200);
     $timeout = 1;
     $DB->get_session_lock($rowid, $timeout);
     // Release the lock on connection1.
     $DB->release_session_lock($rowid);
     // Get the just released lock on connection2.
     $DB2->get_session_lock($rowid, $timeout);
     // Release the lock on connection2.
     $DB2->release_session_lock($rowid);
     $DB2->dispose();
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:40,代码来源:dml_test.php

示例6: instantiate

 /**
  * Call this statically to connect to the DB using the unittest prefix, instantiate
  * the unit test db, store it as a member variable, instantiate $this and use it as the new global $DB.
  */
 public static function instantiate()
 {
     global $CFG, $DB;
     UnitTestDB::$real_db = clone $DB;
     if (empty($CFG->unittestprefix)) {
         print_error("prefixnotset", 'tool_unittest');
     }
     if (empty(UnitTestDB::$DB)) {
         UnitTestDB::$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
         UnitTestDB::$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
     }
     $manager = UnitTestDB::$DB->get_manager();
     if (!$manager->table_exists('user')) {
         print_error('tablesnotsetup', 'tool_unittest');
     }
     $DB = new UnitTestDB();
 }
开发者ID:nigeldaley,项目名称:moodle,代码行数:21,代码来源:simpletestlib.php

示例7: get_drivers

 /**
  * Returns list of fully working database drivers present in system.
  * @return array
  */
 public static function get_drivers()
 {
     return array('' => get_string('choosedots'), 'native/mysqli' => \moodle_database::get_driver_instance('mysqli', 'native')->get_name(), 'native/mariadb' => \moodle_database::get_driver_instance('mariadb', 'native')->get_name(), 'native/pgsql' => \moodle_database::get_driver_instance('pgsql', 'native')->get_name(), 'native/oci' => \moodle_database::get_driver_instance('oci', 'native')->get_name(), 'native/sqlsrv' => \moodle_database::get_driver_instance('sqlsrv', 'native')->get_name(), 'native/mssql' => \moodle_database::get_driver_instance('mssql', 'native')->get_name());
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:8,代码来源:helper.php

示例8: install_print_header



if ($config->stage == INSTALL_DATABASETYPE) {
    $CFG->early_install_lang = false;

    // Finally ask for DB type
    install_print_header($config, get_string('database', 'install'),
                                  get_string('databasetypehead', 'install'),
                                  get_string('databasetypesub', 'install'));

    $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
                       'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
                       'pgsql'  => moodle_database::get_driver_instance('pgsql',  'native'),
                       'oci'    => moodle_database::get_driver_instance('oci',    'native'),
                       'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
                       'mssql'  => moodle_database::get_driver_instance('mssql',  'native'), // FreeTDS driver
                      );

    echo '<div class="userinput">';
    echo '<div class="formrow"><label class="formlabel" for="dbtype">'.get_string('dbtype', 'install').'</label>';
    echo '<select id="dbtype" name="dbtype" class="forminput">';
    $disabled = array();
    $options = array();
    foreach ($databases as $type=>$database) {
        if ($database->driver_installed() !== true) {
            $disabled[$type] = $database;
            continue;
        }
        echo '<option value="'.s($type).'">'.$database->get_name().'</option>';
    }
    if ($disabled) {
开发者ID:rwijaya,项目名称:moodle,代码行数:29,代码来源:install.php

示例9: tool_dbtransfer_get_drivers

/**
 * Returns list of fully working database drivers present in system.
 * @return array
 */
function tool_dbtransfer_get_drivers()
{
    global $CFG;
    $files = new RegexIterator(new DirectoryIterator("{$CFG->libdir}/dml"), '|^.*_moodle_database\\.php$|');
    $drivers = array();
    foreach ($files as $file) {
        $matches = null;
        preg_match('|^([a-z0-9]+)_([a-z]+)_moodle_database\\.php$|', $file->getFilename(), $matches);
        if (!$matches) {
            continue;
        }
        $dbtype = $matches[1];
        $dblibrary = $matches[2];
        if ($dbtype === 'sqlite3') {
            // Blacklist unfinished drivers.
            continue;
        }
        $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, false);
        if ($targetdb->driver_installed() !== true) {
            continue;
        }
        $driver = $dbtype . '/' . $dblibrary;
        $drivers[$driver] = $targetdb->get_name();
    }
    return $drivers;
}
开发者ID:JP-Git,项目名称:moodle,代码行数:30,代码来源:locallib.php

示例10: dispose

 /**
  * Dispose off database connection after pushing any buffered events to the database.
  */
 public function dispose()
 {
     $this->helper_dispose();
     if ($this->extdb) {
         $this->extdb->dispose();
     }
     $this->extdb = null;
 }
开发者ID:educakanchay,项目名称:campus,代码行数:11,代码来源:store.php

示例11: save_discussion

 /**
  * Save the discussion to the DB
  *
  * @param object $discussion
  * @param upload_file $uploader
  */
 public function save_discussion($discussion, upload_file $uploader)
 {
     $message = '';
     $discussion->id = hsuforum_add_discussion($discussion, null, $message);
     $file = $uploader->process_file_upload($discussion->firstpost);
     if (!is_null($file)) {
         $this->db->set_field('hsuforum_posts', 'attachment', 1, array('id' => $discussion->firstpost));
     }
 }
开发者ID:cdsmith-umn,项目名称:moodle-mod_hsuforum,代码行数:15,代码来源:discussion_service.php

示例12: handler_gc

 /**
  * GC session handler.
  *
  * {@see http://php.net/manual/en/function.session-set-save-handler.php}
  *
  * @param int $ignored_maxlifetime moodle uses special timeout rules
  * @return bool success
  */
 public function handler_gc($ignored_maxlifetime)
 {
     // This should do something only if cron is not running properly...
     if (!($stalelifetime = ini_get('session.gc_maxlifetime'))) {
         return true;
     }
     $params = array('purgebefore' => time() - $stalelifetime);
     $this->database->delete_records_select('sessions', 'userid = 0 AND timemodified < :purgebefore', $params);
     return true;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:18,代码来源:database.php

示例13: release_lock

 /**
  * Release a lock that was previously obtained with @lock.
  * @param lock $lock - a lock obtained from this factory.
  * @return boolean - true if the lock is no longer held (including if it was never held).
  */
 public function release_lock(lock $lock)
 {
     $params = array('locktype' => $this->dblockid, 'token' => $lock->get_key());
     $result = $this->db->get_record_sql('SELECT pg_advisory_unlock(:locktype, :token) AS unlocked', $params);
     $result = $result->unlocked === 't';
     if ($result) {
         unset($this->openlocks[$lock->get_key()]);
     }
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:15,代码来源:postgres_lock_factory.php

示例14: commit

 /**
  * Commit new records.
  *
  * @return void
  */
 public function commit()
 {
     $request = (object) array('pid' => getmypid(), 'threadid' => ZEND_THREAD_SAFE ? zend_thread_id() : null, 'uid' => getmyuid(), 'url' => $this->url->out_as_local_url(false), 'hostname' => gethostname(), 'memory' => memory_get_usage(), 'peakmemory' => memory_get_peak_usage());
     // Not supported on Windows until PHP 7
     if (function_exists('getrusage')) {
         $resourceusage = getrusage();
         $request->numswaps = $resourceusage['ru_nswap'];
         $request->numpagefaults = $resourceusage['ru_majflt'];
         $request->usertime = $resourceusage['ru_utime.tv_usec'];
     }
     $request->id = $this->db->insert_record('telemetry_request', $request);
     foreach ($this->additionalstate as $collector) {
         $table = $collector->get_table();
         $records = $collector->get_records();
         foreach ($records as $record) {
             $record->requestid = $request->id;
         }
         $this->db->insert_records($table, $records);
     }
 }
开发者ID:AVADOLearning,项目名称:moodle-local_telemetry,代码行数:25,代码来源:request.php

示例15: extend_lock

 /**
  * Extend a lock that was previously obtained with @lock.
  * @param lock $lock - a lock obtained from this factory.
  * @param int $maxlifetime - the new lifetime for the lock (in seconds).
  * @return boolean - true if the lock was extended.
  */
 public function extend_lock(lock $lock, $maxlifetime = 86400)
 {
     $now = time();
     $expires = $now + $maxlifetime;
     $params = array('expires' => $expires, 'token' => $lock->get_key());
     $sql = 'UPDATE {lock_db}
                 SET
                     expires = :expires,
                 WHERE
                     owner = :token';
     $this->db->execute($sql, $params);
     $countparams = array('owner' => $lock->get_key());
     $result = $this->count_records('lock_db', $countparams);
     return $result === 0;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:21,代码来源:db_record_lock_factory.php


注:本文中的moodle_database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。