当前位置: 首页>>代码示例>>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;未经允许,请勿转载。