當前位置: 首頁>>代碼示例>>PHP>>正文


PHP moodle_database::get_manager方法代碼示例

本文整理匯總了PHP中moodle_database::get_manager方法的典型用法代碼示例。如果您正苦於以下問題:PHP moodle_database::get_manager方法的具體用法?PHP moodle_database::get_manager怎麽用?PHP moodle_database::get_manager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在moodle_database的用法示例。


在下文中一共展示了moodle_database::get_manager方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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_execute

    public function test_execute() {
        $DB = $this->tdb;
        $dbman = $this->tdb->get_manager();

        $table1 = $this->get_test_table('1');
        $tablename1 = $table1->getName();
        $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table1->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, '0');
        $table1->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
        $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $dbman->create_table($table1);

        $table2 = $this->get_test_table('2');
        $tablename2 = $table2->getName();
        $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table2->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $dbman->create_table($table2);

        $DB->insert_record($tablename1, array('course' => 3, 'name' => 'aaa'));
        $DB->insert_record($tablename1, array('course' => 1, 'name' => 'bbb'));
        $DB->insert_record($tablename1, array('course' => 7, 'name' => 'ccc'));
        $DB->insert_record($tablename1, array('course' => 3, 'name' => 'ddd'));

        // select results are ignored
        $sql = "SELECT * FROM {{$tablename1}} WHERE course = :course";
        $this->assertTrue($DB->execute($sql, array('course'=>3)));

        // throw exception on error
        $sql = "XXUPDATE SET XSSD";
        try {
            $DB->execute($sql);
            $this->fail("Expecting an exception, none occurred");
        } catch (Exception $e) {
            $this->assertTrue($e instanceof dml_write_exception);
        }

        // update records
        $sql = "UPDATE {{$tablename1}}
                   SET course = 6
                 WHERE course = ?";
        $this->assertTrue($DB->execute($sql, array('3')));
        $this->assertEqual($DB->count_records($tablename1, array('course' => 6)), 2);

        // insert from one into second table
        $sql = "INSERT INTO {{$tablename2}} (course)

                SELECT course
                  FROM {{$tablename1}}";
        $this->assertTrue($DB->execute($sql));
        $this->assertEqual($DB->count_records($tablename2), 4);
    }
開發者ID:nikita777,項目名稱:moodle,代碼行數:53,代碼來源:testdml.php

示例3: test_execute

 public function test_execute()
 {
     $DB = $this->tdb;
     $dbman = $this->tdb->get_manager();
     $table1 = $this->get_test_table('1');
     $tablename1 = $table1->getName();
     $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
     $table1->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, '0');
     $table1->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
     $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
     $dbman->create_table($table1);
     $table2 = $this->get_test_table('2');
     $tablename2 = $table2->getName();
     $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
     $table2->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
     $dbman->create_table($table2);
     $DB->insert_record($tablename1, array('course' => 3, 'name' => 'aaa'));
     $DB->insert_record($tablename1, array('course' => 1, 'name' => 'bbb'));
     $DB->insert_record($tablename1, array('course' => 7, 'name' => 'ccc'));
     $DB->insert_record($tablename1, array('course' => 3, 'name' => 'ddd'));
     // select results are ignored
     $sql = "SELECT * FROM {{$tablename1}} WHERE course = :course";
     $this->assertTrue($DB->execute($sql, array('course' => 3)));
     // throw exception on error
     $sql = "XXUPDATE SET XSSD";
     try {
         $DB->execute($sql);
         $this->fail("Expecting an exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof dml_exception);
     }
     // update records
     $sql = "UPDATE {{$tablename1}}\n                   SET course = 6\n                 WHERE course = ?";
     $this->assertTrue($DB->execute($sql, array('3')));
     $this->assertEqual($DB->count_records($tablename1, array('course' => 6)), 2);
     // update records with subquery condition
     // confirm that the option not using table aliases is cross-db
     $sql = "UPDATE {{$tablename1}}\n                   SET course = 0\n                 WHERE NOT EXISTS (\n                           SELECT course\n                             FROM {{$tablename2}} tbl2\n                            WHERE tbl2.course = {{$tablename1}}.course\n                              AND 1 = 0)";
     // Really we don't update anything, but verify the syntax is allowed
     $this->assertTrue($DB->execute($sql));
     // insert from one into second table
     $sql = "INSERT INTO {{$tablename2}} (course)\n\n                SELECT course\n                  FROM {{$tablename1}}";
     $this->assertTrue($DB->execute($sql));
     $this->assertEqual($DB->count_records($tablename2), 4);
 }
開發者ID:nickread,項目名稱:moodle,代碼行數:47,代碼來源:testdml.php

示例4: 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


注:本文中的moodle_database::get_manager方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。