本文整理汇总了PHP中moodle_database::get_driver_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_database::get_driver_instance方法的具体用法?PHP moodle_database::get_driver_instance怎么用?PHP moodle_database::get_driver_instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodle_database
的用法示例。
在下文中一共展示了moodle_database::get_driver_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Setup the Database.
*
* @return bool
*/
protected function init()
{
if (isset($this->extdb)) {
return !empty($this->extdb);
}
$dbdriver = $this->get_config('dbdriver');
if (empty($dbdriver)) {
$this->extdb = false;
return false;
}
list($dblibrary, $dbtype) = explode('/', $dbdriver);
if (!($db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true))) {
debugging("Unknown driver {$dblibrary}/{$dbtype}", DEBUG_DEVELOPER);
$this->extdb = false;
return false;
}
$dboptions = array();
$dboptions['dbpersist'] = $this->get_config('dbpersist', '0');
$dboptions['dbsocket'] = $this->get_config('dbsocket', '');
$dboptions['dbport'] = $this->get_config('dbport', '');
$dboptions['dbschema'] = $this->get_config('dbschema', '');
$dboptions['dbcollation'] = $this->get_config('dbcollation', '');
try {
$db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'), $this->get_config('dbname'), false, $dboptions);
$tables = $db->get_tables();
if (!in_array($this->get_config('dbtable'), $tables)) {
debugging('Cannot find the specified table', DEBUG_DEVELOPER);
$this->extdb = false;
return false;
}
} catch (\moodle_exception $e) {
debugging('Cannot connect to external database: ' . $e->getMessage(), DEBUG_DEVELOPER);
$this->extdb = false;
return false;
}
$this->extdb = $db;
return true;
}
示例2: 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;
}
示例3: setup_DB
/**
* Sets up global $DB moodle_database instance
*
* @global object
* @global object
* @return void
*/
function setup_DB()
{
global $CFG, $DB;
if (isset($DB)) {
return;
}
if (!isset($CFG->dbuser)) {
$CFG->dbuser = '';
}
if (!isset($CFG->dbpass)) {
$CFG->dbpass = '';
}
if (!isset($CFG->dbname)) {
$CFG->dbname = '';
}
if (!isset($CFG->dblibrary)) {
$CFG->dblibrary = 'native';
// use new drivers instead of the old adodb driver names
switch ($CFG->dbtype) {
case 'postgres7':
$CFG->dbtype = 'pgsql';
break;
case 'mssql_n':
$CFG->dbtype = 'mssql';
break;
case 'oci8po':
$CFG->dbtype = 'oci';
break;
case 'mysql':
$CFG->dbtype = 'mysqli';
break;
}
}
if (!isset($CFG->dboptions)) {
$CFG->dboptions = array();
}
if (isset($CFG->dbpersist)) {
$CFG->dboptions['dbpersist'] = $CFG->dbpersist;
}
if (!($DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary))) {
throw new dml_exception('dbdriverproblem', "Unknown driver {$CFG->dblibrary}/{$CFG->dbtype}");
}
try {
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions);
} catch (moodle_exception $e) {
if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
if (file_exists($CFG->dataroot . '/emailcount')) {
$fp = @fopen($CFG->dataroot . '/emailcount', 'r');
$content = @fread($fp, 24);
@fclose($fp);
if (time() - (int) $content > 600) {
//email directly rather than using messaging
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, 'Connection error: ' . $CFG->wwwroot);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
} else {
//email directly rather than using messaging
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, 'Connection error: ' . $CFG->wwwroot);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
}
// rethrow the exception
throw $e;
}
$CFG->dbfamily = $DB->get_dbfamily();
// TODO: BC only for now
return true;
}
示例4: 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();
}
示例5: test_concurrent_autosaves
public function test_concurrent_autosaves()
{
// This test simulates the following scenario:
// 1. Student opens a page of the quiz in two separate browser.
// 2. Autosave starts in both at the same time.
// In this situation, one autosave will work, and the other one will
// get a unique key violation error. This is OK.
global $DB;
// 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);
// Since we need to commit our transactions in a given order, close the
// standard unit test transaction.
$this->preventResetByRollback();
$this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category();
$question = $generator->create_question('shortanswer', null, array('category' => $cat->id));
// Start attempt at a shortanswer question.
$q = question_bank::load_question($question->id);
$this->start_attempt_at_question($q, 'deferredfeedback', 1);
$this->save_quba();
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->check_step_count(1);
// Start to process an autosave on $DB.
$transaction = $DB->start_delegated_transaction();
$this->load_quba($DB);
$this->process_autosave(array('answer' => 'autosaved response 1'));
$this->check_current_state(question_state::$complete);
$this->check_current_mark(null);
$this->check_step_count(2);
$this->save_quba($DB);
// Don't commit the transaction yet.
// Now process a real submit on $DB2 (using a different response).
$transaction2 = $DB2->start_delegated_transaction();
$this->load_quba($DB2);
$this->process_autosave(array('answer' => 'autosaved response 2'));
$this->check_current_state(question_state::$complete);
$this->check_current_mark(null);
$this->check_step_count(2);
// Now commit the first transaction.
$transaction->allow_commit();
// Now commit the other transaction.
$this->setExpectedException('dml_write_exception');
$this->save_quba($DB2);
$transaction2->allow_commit();
// Now re-load and check how that is re-displayed.
$this->load_quba();
$this->check_current_state(question_state::$complete);
$this->check_current_mark(null);
$this->check_step_count(2);
$this->render();
$this->check_output_contains_text_input('answer', 'autosaved response 1');
$this->check_output_contains_hidden_input(':sequencecheck', 1);
$DB2->dispose();
}
示例6: 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();
}
示例7: 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_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_table($table);
// Drop temp table.
$this->assertFalse($dbman->table_exists('test_table1'));
}
示例8: get_other_db
/**
* Initialises the database connection for the 'otherdb' cache type.
* @return moodle_database the DB connection to use.
*/
protected static function get_other_db()
{
if (!is_null(self::$otherdb)) {
return self::$otherdb;
}
$dboptions = array();
if (!empty(self::$config->cascachedbsocket)) {
$dboptions['dbsocket'] = true;
}
self::$otherdb = moodle_database::get_driver_instance(self::$config->cascachedbtype, self::$config->cascachedblibrary);
self::$otherdb->connect(self::$config->cascachedbhost, self::$config->cascachedbuser, self::$config->cascachedbpass, self::$config->cascachedbname, self::$config->cascachedbprefix, $dboptions);
return self::$otherdb;
}
示例9: require_capability
require_capability('tool/unittest:execute', $syscontext);
$baseurl = new moodle_url('/admin/tool/unittest/other/filtersettingsperformancetester.php');
$title = 'filter_get_active_in_context performance test';
$PAGE->set_url($baseurl);
$PAGE->set_context($syscontext);
$PAGE->navbar->add($title);
$PAGE->set_title($title);
$PAGE->set_heading($title);
echo $OUTPUT->header();
// Complain if we get this far and $CFG->unittestprefix is not set.
if (empty($CFG->unittestprefix)) {
throw new coding_exception('This page requires $CFG->unittestprefix to be set in config.php.');
}
$requiredtables = array('context', 'filter_active', 'filter_config');
$realdb = $DB;
$testdb = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
$testdb->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
$DB = $testdb;
$dbman = $testdb->get_manager();
$issetup = 0;
foreach ($requiredtables as $table) {
if ($dbman->table_exists(new xmldb_table($table))) {
$issetup++;
}
}
switch (optional_param('action', '', PARAM_ACTION)) {
case 'setup':
require_sesskey();
if ($issetup == 0) {
foreach ($requiredtables as $table) {
$dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/lib/db/install.xml', $table);
示例10: setup_ExternalDB
/**
* Sets up global $DB moodle_database instance
*
* @global stdClass $CFG The global configuration instance.
* @see config.php
* @see config-dist.php
* @global stdClass $DB The global moodle_database instance.
* @return void|bool Returns true when finished setting up $DB. Returns void when $DB has already been set.
*/
function setup_ExternalDB()
{
global $CFG, $DB, $remotedb;
// Use a custom $remotedb (and not current system's $DB) if set - code sourced from configurable
// Reports plugin.
$remotedbhost = get_config('report_myfeedback', 'dbhost');
$remotedbname = get_config('report_myfeedback', 'dbname');
$remotedbuser = get_config('report_myfeedback', 'dbuser');
$remotedbpass = get_config('report_myfeedback', 'dbpass');
if (empty($remotedbhost) or empty($remotedbname) or empty($remotedbuser)) {
$remotedb = $DB;
setup_DB();
} else {
//
if (!isset($CFG->dblibrary)) {
$CFG->dblibrary = 'native';
// use new drivers instead of the old adodb driver names
switch ($CFG->dbtype) {
case 'postgres7':
$CFG->dbtype = 'pgsql';
break;
case 'mssql_n':
$CFG->dbtype = 'mssql';
break;
case 'oci8po':
$CFG->dbtype = 'oci';
break;
case 'mysql':
$CFG->dbtype = 'mysqli';
break;
}
}
if (!isset($CFG->dboptions)) {
$CFG->dboptions = array();
}
if (isset($CFG->dbpersist)) {
$CFG->dboptions['dbpersist'] = $CFG->dbpersist;
}
if (!($remotedb = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary))) {
throw new dml_exception('dbdriverproblem', "Unknown driver {$CFG->dblibrary}/{$CFG->dbtype}");
}
try {
$remotedb->connect($remotedbhost, $remotedbuser, $remotedbpass, $remotedbname, $CFG->prefix, $CFG->dboptions);
} catch (moodle_exception $e) {
if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
$body = "Connection error: " . $CFG->wwwroot . "\n\nInfo:" . "\n\tError code: " . $e->errorcode . "\n\tDebug info: " . $e->debuginfo . "\n\tServer: " . $_SERVER['SERVER_NAME'] . " (" . $_SERVER['SERVER_ADDR'] . ")";
if (file_exists($CFG->dataroot . '/emailcount')) {
$fp = @fopen($CFG->dataroot . '/emailcount', 'r');
$content = @fread($fp, 24);
@fclose($fp);
if (time() - (int) $content > 600) {
//email directly rather than using messaging
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, $body);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
} else {
//email directly rather than using messaging
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, $body);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
}
// rethrow the exception
throw $e;
}
$CFG->dbfamily = $remotedb->get_dbfamily();
// TODO: BC only for now
return true;
}
return false;
}
示例11: vmoodle_setup_DB
/**
* Sets up global $DB moodle_database instance
*
* @global stdClass $CFG The global configuration instance.
* @see config.php
* @see config-dist.php
* @global stdClass $DB The global moodle_database instance.
* @return void|bool Returns true when finished setting up $DB. Returns void when $DB has already been set.
*/
function vmoodle_setup_DB($vmoodle)
{
global $CFG;
if (!isset($vmoodle->vdblogin)) {
$vmoodle->vdblogin = '';
}
if (!isset($vmoodle->vdbpass)) {
$vmoodle->vdbpass = '';
}
if (!isset($vmoodle->vdbname)) {
$vmoodle->vdbname = '';
}
if (!isset($vmoodle->dblibrary)) {
$vmoodle->dblibrary = 'native';
// Use new drivers instead of the old adodb driver names.
switch ($vmoodle->vdbtype) {
case 'postgres7':
$vmoodle->vdbtype = 'pgsql';
break;
case 'mssql_n':
$vmoodle->vdbtype = 'mssql';
break;
case 'oci8po':
$vmoodle->vdbtype = 'oci';
break;
case 'mysql':
$vmoodle->vdbtype = 'mysqli';
break;
}
}
if (!isset($vmoodle->dboptions)) {
$vmoodle->dboptions = array();
}
if (isset($vmoodle->vdbpersist)) {
$vmoodle->dboptions['dbpersist'] = $vmoodle->vdbpersist;
}
if (!($vdb = moodle_database::get_driver_instance($vmoodle->vdbtype, $vmoodle->dblibrary))) {
throw new dml_exception('dbdriverproblem', "Unknown driver {$vmoodle->dblibrary}/{$vmoodle->dbtype}");
}
$vdb->connect($vmoodle->vdbhost, $vmoodle->vdblogin, $vmoodle->vdbpass, $vmoodle->vdbname, $vmoodle->vdbprefix, $vmoodle->dboptions);
$vmoodle->vdbfamily = $vdb->get_dbfamily();
// TODO: BC only for now
return $vdb;
}
示例12: setup_DB
/**
* Sets up global $DB moodle_database instance
* @return void
*/
function setup_DB()
{
global $CFG, $DB;
if (isset($DB)) {
return;
}
if (!isset($CFG->dbuser)) {
$CFG->dbuser = '';
}
if (!isset($CFG->dbpass)) {
$CFG->dbpass = '';
}
if (!isset($CFG->dbname)) {
$CFG->dbname = '';
}
if (!isset($CFG->dblibrary)) {
switch ($CFG->dbtype) {
case 'postgres7':
$CFG->dbtype = 'pgsql';
// continue, no break here
// continue, no break here
case 'pgsql':
$CFG->dblibrary = 'native';
break;
case 'mysql':
if (!extension_loaded('mysqli')) {
$CFG->dblibrary = 'adodb';
break;
}
$CFG->dbtype = 'mysqli';
// continue, no break here
// continue, no break here
case 'mysqli':
$CFG->dblibrary = 'native';
break;
default:
// the rest of drivers is not converted yet - keep adodb for now
$CFG->dblibrary = 'adodb';
}
}
if (!isset($CFG->dboptions)) {
$CFG->dboptions = array();
}
if (isset($CFG->dbpersist)) {
$CFG->dboptions['dbpersist'] = $CFG->dbpersist;
}
if (!($DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary))) {
throw new dml_exception('dbdriverproblem', "Unknown driver {$CFG->dblibrary}/{$CFG->dbtype}");
}
try {
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions);
} catch (moodle_exception $e) {
if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
if (file_exists($CFG->dataroot . '/emailcount')) {
$fp = @fopen($CFG->dataroot . '/emailcount', 'r');
$content = @fread($fp, 24);
@fclose($fp);
if (time() - (int) $content > 600) {
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, 'Connection error: ' . $CFG->wwwroot);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
} else {
@mail($CFG->emailconnectionerrorsto, 'WARNING: Database connection error: ' . $CFG->wwwroot, 'Connection error: ' . $CFG->wwwroot);
$fp = @fopen($CFG->dataroot . '/emailcount', 'w');
@fwrite($fp, time());
}
}
// rethrow the exception
throw $e;
}
$CFG->dbfamily = $DB->get_dbfamily();
// TODO: BC only for now
return true;
}
示例13: 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());
}
示例14: 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 efectively 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 excuted, but here for safety
$this->fail('An Exception is missing, expected due to session lock acquired.');
} catch (exception $e) {
$this->assertTrue($e instanceof dml_sessionwait_exception);
$DB->release_session_lock($rowid);
// Release lock on connection1
}
// Testing that releasing a lock efectively 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();
}
示例15: cli_heading
}
if (!isset($options['dbport'])) {
cli_heading(get_string('dbport', 'install'));
$options['dbport'] = cli_input(get_string('clitypevalue', 'admin'));
}
if ($CFG->ostype !== 'WINDOWS') {
if (!isset($options['dbsocket'])) {
cli_heading(get_string('databasesocket', 'install'));
$options['dbsocket'] = cli_input(get_string('clitypevalue', 'admin'));
}
}
$a = (object) array('dbtypefrom' => $CFG->dbtype, 'dbtype' => $options['dbtype'], 'dbname' => $options['dbname'], 'dbhost' => $options['dbhost']);
cli_heading(get_string('transferringdbto', 'tool_dbtransfer', $a));
// Try target DB connection.
$problem = '';
$targetdb = moodle_database::get_driver_instance($options['dbtype'], $options['dblibrary']);
$dboptions = array();
if ($options['dbport']) {
$dboptions['dbport'] = $options['dbport'];
}
if ($options['dbsocket']) {
$dboptions['dbsocket'] = $options['dbsocket'];
}
try {
$targetdb->connect($options['dbhost'], $options['dbuser'], $options['dbpass'], $options['dbname'], $options['prefix'], $dboptions);
if ($targetdb->get_tables()) {
$problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
}
} catch (moodle_exception $e) {
$problem .= $e->debuginfo . "\n\n";
$problem .= get_string('notargetconectexception', 'tool_dbtransfer');