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


PHP DB::get_conn方法代码示例

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


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

示例1: testMultipleRowInsert

 public function testMultipleRowInsert()
 {
     $query = SQLInsert::create('"SQLInsertTestBase"');
     $query->addRow(array('"Title"' => 'First Object', '"Age"' => 10, '"Description"' => 'First the worst'));
     $query->addRow(array('"Title"' => 'Second object', '"Age"' => 12));
     $sql = $query->sql($parameters);
     // Only test this case if using the default query builder
     if (get_class(DB::get_conn()->getQueryBuilder()) === 'DBQueryBuilder') {
         $this->assertSQLEquals('INSERT INTO "SQLInsertTestBase" ("Title", "Age", "Description") VALUES (?, ?, ?), (?, ?, ?)', $sql);
     }
     $this->assertEquals(array('First Object', 10, 'First the worst', 'Second object', 12, null), $parameters);
     $query->execute();
     $this->assertEquals(2, DB::affected_rows());
     // Check inserted objects are correct
     $firstObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'First Object'), false);
     $this->assertNotEmpty($firstObject);
     $this->assertEquals($firstObject->Title, 'First Object');
     $this->assertEquals($firstObject->Age, 10);
     $this->assertEquals($firstObject->Description, 'First the worst');
     $secondObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'Second object'), false);
     $this->assertNotEmpty($secondObject);
     $this->assertEquals($secondObject->Title, 'Second object');
     $this->assertEquals($secondObject->Age, 12);
     $this->assertEmpty($secondObject->Description);
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:25,代码来源:SQLInsertTest.php

示例2: artefacts

 /**
  * @return array
  */
 private function artefacts()
 {
     $oldschema = [];
     $newschema = [];
     $current = DB::get_conn()->getSelectedDatabase();
     foreach (DB::table_list() as $lowercase => $dbtablename) {
         $oldschema[$dbtablename] = DB::field_list($dbtablename);
     }
     $test = new SapphireTest();
     $test->create_temp_db();
     foreach (DB::table_list() as $lowercase => $dbtablename) {
         $newschema[$lowercase] = DB::field_list($dbtablename);
     }
     $test->kill_temp_db();
     DB::get_conn()->selectDatabase($current);
     $artefacts = [];
     foreach ($oldschema as $table => $fields) {
         if (!isset($newschema[strtolower($table)])) {
             $artefacts[$table] = $table;
             continue;
         }
         foreach ($fields as $field => $spec) {
             if (!isset($newschema[strtolower($table)][$field])) {
                 $artefacts[$table][$field] = $field;
             }
         }
     }
     return $artefacts;
 }
开发者ID:oddnoc,项目名称:silverstripe-artefactcleaner,代码行数:32,代码来源:ArtefactCleanTask.php

示例3: DBConn

 /**
  * Get the DB connection in a SS 3.1 and 3.2+ compatible way
  * @param string $name
  * @return SS_Database
  */
 public static function DBConn($name = 'default')
 {
     if (method_exists('DB', 'get_conn')) {
         return DB::get_conn($name);
     }
     return DB::getConn($name);
 }
开发者ID:burnbright,项目名称:silverstripe-shop,代码行数:12,代码来源:ShopTools.php

示例4: testFilter

 public function testFilter()
 {
     if (DB::get_conn() instanceof MySQLDatabase) {
         $baseQuery = FulltextFilterTest_DataObject::get();
         $this->assertEquals(3, $baseQuery->count(), "FulltextFilterTest_DataObject count does not match.");
         // First we'll text the 'SearchFields' which has been set using an array
         $search = $baseQuery->filter("SearchFields:fulltext", 'SilverStripe');
         $this->assertEquals(1, $search->count());
         $search = $baseQuery->exclude("SearchFields:fulltext", "SilverStripe");
         $this->assertEquals(2, $search->count());
         // Now we'll run the same tests on 'OtherSearchFields' which should yield the same resutls
         // but has been set using a string.
         $search = $baseQuery->filter("OtherSearchFields:fulltext", 'SilverStripe');
         $this->assertEquals(1, $search->count());
         $search = $baseQuery->exclude("OtherSearchFields:fulltext", "SilverStripe");
         $this->assertEquals(2, $search->count());
         // Search on a single field
         $search = $baseQuery->filter("ColumnE:fulltext", 'Dragons');
         $this->assertEquals(1, $search->count());
         $search = $baseQuery->exclude("ColumnE:fulltext", "Dragons");
         $this->assertEquals(2, $search->count());
     } else {
         $this->markTestSkipped("FulltextFilter only supports MySQL syntax.");
     }
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:25,代码来源:FulltextFilterTest.php

示例5: logVisit

 protected function logVisit()
 {
     if (!Security::database_is_ready()) {
         return;
     }
     DB::query(sprintf('UPDATE "Member" SET "LastVisited" = %s, "NumVisit" = "NumVisit" + 1 WHERE "ID" = %d', DB::get_conn()->now(), $this->owner->ID));
 }
开发者ID:andrelohmann,项目名称:roof-for-refugees.org,代码行数:7,代码来源:VisitsMemberExtension.php

示例6: testReadOnlyTransaction

 function testReadOnlyTransaction()
 {
     if (DB::get_conn()->supportsTransactions() == true && DB::get_conn() instanceof PostgreSQLDatabase) {
         $page = new Page();
         $page->Title = 'Read only success';
         $page->write();
         DB::get_conn()->transactionStart('READ ONLY');
         try {
             $page = new Page();
             $page->Title = 'Read only page failed';
             $page->write();
         } catch (Exception $e) {
             //could not write this record
             //We need to do a rollback or a commit otherwise we'll get error messages
             DB::get_conn()->transactionRollback();
         }
         DB::get_conn()->transactionEnd();
         DataObject::flush_and_destroy_cache();
         $success = DataObject::get('Page', "\"Title\"='Read only success'");
         $fail = DataObject::get('Page', "\"Title\"='Read only page failed'");
         //This page should be in the system
         $this->assertTrue(is_object($success) && $success->exists());
         //This page should NOT exist, we had 'read only' permissions
         $this->assertFalse(is_object($fail) && $fail->exists());
     } else {
         $this->markTestSkipped('Current database is not PostgreSQL');
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-postgresql,代码行数:28,代码来源:PostgreSQLDatabaseTest.php

示例7: testCreateWithTransaction

 public function testCreateWithTransaction()
 {
     if (DB::get_conn()->supportsTransactions() == true) {
         DB::get_conn()->transactionStart();
         $obj = new TransactionTest_Object();
         $obj->Title = 'First page';
         $obj->write();
         $obj = new TransactionTest_Object();
         $obj->Title = 'Second page';
         $obj->write();
         //Create a savepoint here:
         DB::get_conn()->transactionSavepoint('rollback');
         $obj = new TransactionTest_Object();
         $obj->Title = 'Third page';
         $obj->write();
         $obj = new TransactionTest_Object();
         $obj->Title = 'Fourth page';
         $obj->write();
         //Revert to a savepoint:
         DB::get_conn()->transactionRollback('rollback');
         DB::get_conn()->transactionEnd();
         $first = DataObject::get('TransactionTest_Object', "\"Title\"='First page'");
         $second = DataObject::get('TransactionTest_Object', "\"Title\"='Second page'");
         $third = DataObject::get('TransactionTest_Object', "\"Title\"='Third page'");
         $fourth = DataObject::get('TransactionTest_Object', "\"Title\"='Fourth page'");
         //These pages should be in the system
         $this->assertTrue(is_object($first) && $first->exists());
         $this->assertTrue(is_object($second) && $second->exists());
         //These pages should NOT exist, we reverted to a savepoint:
         $this->assertFalse(is_object($third) && $third->exists());
         $this->assertFalse(is_object($fourth) && $fourth->exists());
     } else {
         $this->markTestSkipped('Current database does not support transactions');
     }
 }
开发者ID:steiha,项目名称:silverstripe-framework,代码行数:35,代码来源:TransactionTest.php

示例8: testQueriedColumnsFromSubTable

 public function testQueriedColumnsFromSubTable()
 {
     $db = DB::get_conn();
     $playerList = new DataList('DataObjectTest_SubTeam');
     $playerList = $playerList->setQueriedColumns(array('SubclassDatabaseField'));
     $expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."LastEdited", ' . '"DataObjectTest_Team"."Created", "DataObjectTest_SubTeam"."SubclassDatabaseField", ' . '"DataObjectTest_Team"."ID", CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN ' . '"DataObjectTest_Team"."ClassName" ELSE ' . $db->quoteString('DataObjectTest_Team') . ' END ' . 'AS "RecordClassName", "DataObjectTest_Team"."Title" ' . 'FROM "DataObjectTest_Team" LEFT JOIN "DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = ' . '"DataObjectTest_Team"."ID" WHERE ("DataObjectTest_Team"."ClassName" IN (?)) ' . 'ORDER BY "DataObjectTest_Team"."Title" ASC';
     $this->assertSQLEquals($expected, $playerList->sql($parameters));
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:8,代码来源:DataObjectLazyLoadingTest.php

示例9: requireField

 public function requireField()
 {
     // HACK: MSSQL does not support double so we're using float instead
     // @todo This should go into MSSQLDatabase ideally somehow
     if (DB::get_conn() instanceof MySQLDatabase) {
         DB::require_field($this->tableName, $this->name, "double");
     } else {
         DB::require_field($this->tableName, $this->name, "float");
     }
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:10,代码来源:Double.php

示例10: getLocation

 public function getLocation($ip, $ipNumber)
 {
     $conn = DB::get_conn();
     $addressType = IpToLocation::addr_type($ip);
     $sql = "SELECT\n\t\t\t\t\t\t`ip_start` AS IPFrom,\n\t\t\t\t\t\t`ip_end` AS IPTo,\n\t\t\t\t\t\t`country` AS Country,\n\t\t\t\t\t\t`stateprov` AS Region,\n\t\t\t\t\t\t`city` AS City\n\t\t\t\t \tFROM\n\t\t\t\t\t\t`dbip_lookup`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\taddr_type = '{$addressType}'\n\t\t\t\t\t\tAND ip_start <= '" . $conn->escapeString($ipNumber) . "'\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tip_start DESC\n\t\t\t\t\tLIMIT 1";
     $res = DB::query($sql);
     while ($row = $res->nextRecord()) {
         $location = new IpToLocation($row);
         $this->debugLocation($location);
         return $location;
     }
 }
开发者ID:silverstripers,项目名称:continental-content,代码行数:12,代码来源:IPDBCOM_IpParser.php

示例11: excludeMany

 protected function excludeMany(DataQuery $query)
 {
     $this->model = $query->applyRelation($this->relation);
     $values = $this->getValue();
     $comparisonClause = DB::get_conn()->comparisonClause($this->getDbName(), null, false, true, $this->getCaseSensitive(), true);
     $parameters = array();
     foreach ($values as $value) {
         $parameters[] = $this->getMatchPattern($value);
     }
     // Since query connective is ambiguous, use AND explicitly here
     $count = count($values);
     $predicate = implode(' AND ', array_fill(0, $count, $comparisonClause));
     return $query->where(array($predicate => $parameters));
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:14,代码来源:PartialMatchFilter.php

示例12: init

 /**
  * Initialisation function that is run before any action on the controller is called.
  *
  * @uses BasicAuth::requireLogin()
  */
 public function init()
 {
     if ($this->basicAuthEnabled) {
         BasicAuth::protect_site_if_necessary();
     }
     // Directly access the session variable just in case the Group or Member tables don't yet exist
     if (Member::config()->log_last_visited) {
         Deprecation::notice('4.0', 'Member::$LastVisited is deprecated. From 4.0 onwards you should implement this as a custom extension');
         if (Session::get('loggedInAs') && Security::database_is_ready() && ($member = Member::currentUser())) {
             DB::prepared_query(sprintf('UPDATE "Member" SET "LastVisited" = %s WHERE "ID" = ?', DB::get_conn()->now()), array($member->ID));
         }
     }
     // This is used to test that subordinate controllers are actually calling parent::init() - a common bug
     $this->baseInitCalled = true;
 }
开发者ID:miamollie,项目名称:echoAerial,代码行数:20,代码来源:Controller.php

示例13: run

 public function run($request)
 {
     $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/dbip-city.csv';
     if (!file_exists($strCSVPath)) {
         echo "<p>I cant find the dbip-city.csv file to import any data.<br>\n\t\t\t\tPlease download any database from <a href='https://db-ip.com/db/'>https://db-ip.com/db/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`Region`,`City`\n\t\t\t\t</p>";
         //"0.0.0.0","0.255.255.255","US","California","Los Angeles"
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportDBIPcom?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             increase_time_limit_to();
             //
             // this needs varbinary fields so create the table here
             //
             $arr = DB::table_list();
             if (!in_array('dbip_lookup', $arr)) {
                 $strSQL = "CREATE TABLE `dbip_lookup` (\n\t\t\t\t\t  `addr_type` enum('ipv4','ipv6') NOT NULL,\n\t\t\t\t\t  `ip_start` varbinary(16) NOT NULL,\n\t\t\t\t\t  `ip_end` varbinary(16) NOT NULL,\n\t\t\t\t\t  `country` char(2) NOT NULL,\n\t\t\t\t\t  `stateprov` varchar(80) NOT NULL,\n\t\t\t\t\t  `city` varchar(80) NOT NULL,\n\t\t\t\t\t  PRIMARY KEY (`ip_start`)\n\t\t\t\t\t);";
                 DB::query($strSQL);
             }
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `dbip_lookup`;');
             }
             $conn = DB::get_conn();
             if ($conn->supportsTransactions()) {
                 $conn->transactionStart();
             }
             $handle = fopen($strCSVPath, "r");
             if ($handle) {
                 while (($line = fgets($handle)) !== false) {
                     $line = str_replace('","', '___', $line);
                     $line = str_replace('"', '', $line);
                     $arrParts = Convert::raw2sql(explode("___", $line));
                     $vals = array('addr_type' => "'" . IpToLocation::addr_type($arrParts[0]) . "'", 'ip_start' => "'" . $conn->escapeString(ContinentalContentUtils::IPAddressToIPNumber($arrParts[0])) . "'", 'ip_end' => "'" . $conn->escapeString(ContinentalContentUtils::IPAddressToIPNumber($arrParts[1])) . "'", 'country' => "'" . $arrParts[2] . "'", 'stateprov' => "'" . $arrParts[3] . "'", 'city' => "'" . $arrParts[4] . "'");
                     $fields = array_keys($vals);
                     DB::query('INSERT INTO `dbip_lookup` (`' . implode('`,`', $fields) . '`) VALUES (' . implode(',', $vals) . ')');
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
             if ($conn->supportsTransactions()) {
                 $conn->transactionEnd();
             }
         }
     }
 }
开发者ID:silverstripers,项目名称:continental-content,代码行数:47,代码来源:ImportDBIPcom.php

示例14: testFieldsDontRerequestChanges

 /**
  * Check that once a schema has been generated, then it doesn't need any more updating
  */
 public function testFieldsDontRerequestChanges()
 {
     // These are MySQL specific :-S
     if (DB::get_conn() instanceof MySQLDatabase) {
         $schema = DB::get_schema();
         $test = $this;
         DB::quiet();
         // Verify that it doesn't need to be recreated
         $schema->schemaUpdate(function () use($test, $schema) {
             $obj = new MySQLDatabaseTest_DO();
             $obj->requireTable();
             $needsUpdating = $schema->doesSchemaNeedUpdating();
             $schema->cancelSchemaUpdate();
             $test->assertFalse($needsUpdating);
         });
     }
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:20,代码来源:MySQLDatabaseTest.php

示例15: testLeftJoinParameterised

 public function testLeftJoinParameterised()
 {
     $db = DB::get_conn();
     $list = DataObjectTest_TeamComment::get();
     $list = $list->leftJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID" ' . 'AND "DataObjectTest_Team"."Title" LIKE ?', 'Team', 20, array('Team%'));
     $expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", ' . '"DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Created", ' . '"DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", ' . '"DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", ' . 'CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL' . ' THEN "DataObjectTest_TeamComment"."ClassName" ELSE ' . $db->quoteString('DataObjectTest_TeamComment') . ' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" LEFT JOIN ' . '"DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = ' . '"DataObjectTest_TeamComment"."TeamID" ' . 'AND "DataObjectTest_Team"."Title" LIKE ?' . ' ORDER BY "DataObjectTest_TeamComment"."Name" ASC';
     $this->assertSQLEquals($expected, $list->sql($parameters));
     $this->assertEquals(array('Team%'), $parameters);
 }
开发者ID:miamollie,项目名称:echoAerial,代码行数:9,代码来源:DataListTest.php


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