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


PHP OA_DB::setCharset方法代码示例

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


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

示例1: test_convertEncoding

 /**
  * Test convertEncoding()
  *
  */
 function test_convertEncoding()
 {
     // Force client charset to latin1 so that the behaviour is similar to a real latin1 database
     // even if the database is encoded in utf8. At first we tried to drop the database an recreate
     // a latin1 encoded database, but PgSQL doesn't allow LATIN1 databases if the locale is set to
     // UTF-8.
     $GLOBALS['_MAX']['CONF']['databaseCharset'] = array('checkComplete' => true, 'clientCharset' => 'latin1');
     // However MySQL versions < 4.1.2 didn't support charsets, so we don't need to do that
     // and assume that a database can store any 8bit data (which is in fact true)
     if ($this->oDbh->dbsyntax == 'mysql') {
         $aVersion = $this->oDbh->getServerVersion();
         if (version_compare($aVersion['native'], '4.1.2', '<')) {
             $GLOBALS['_MAX']['CONF']['databaseCharset']['clientCharset'] = '';
         }
     }
     // Set client charset
     OA_DB::setCharset($this->oDbh);
     // These tables are required for the encoding migration
     $aTables = array('acls', 'acls_channel', 'ad_zone_assoc', 'affiliates', 'affiliates_extra', 'agency', 'application_variable', 'banners', 'campaigns', 'channel', 'clients', 'preference', 'session', 'tracker_append', 'trackers', 'userlog', 'variables', 'zones');
     // These tables are referenced by schema changes between 515 and 546, therefore need to be created
     $aOtherTables = array('preference_publisher', 'accounts', 'users', 'account_user_assoc');
     //array('preference', 'data_raw_tracker_click', 'data_summary_zone_country_daily', 'data_summary_zone_country_forecast', 'data_summary_zone_country_monthly', 'data_summary_zone_domain_page_daily', 'data_summary_zone_domain_page_forecast', 'data_summary_zone_domain_page_monthly', 'data_summary_zone_site_keyword_daily', 'data_summary_zone_site_keyword_forecast', 'data_summary_zone_site_keyword_monthly', 'data_summary_zone_source_daily', 'data_summary_zone_source_forecast', 'data_summary_zone_source_monthly', 'preference_advertiser', 'preference_publisher');
     $this->initDatabase(543, array_merge($aTables, $aOtherTables));
     $this->aIds = TestEnv::loadData('encoding_schema_543', 'mdb2schema');
     // MD5s verified manually setting the terminal encoding to the right encoding.
     $expected = array('latin1_utf8' => array(0 => array('campaignid' => $this->aIds['campaigns'][1], 'md5' => '1698982c38317c8c42ae4772bbee8f44'), 1 => array('campaignid' => $this->aIds['campaigns'][2], 'md5' => '317f56003783a2a9284306eb57fe8146'), 2 => array('campaignid' => $this->aIds['campaigns'][3], 'md5' => 'fa419947d425b10bd2485e090f4cae60'), 3 => array('campaignid' => $this->aIds['campaigns'][4], 'md5' => '32395feef462f13071c2a2fe5e44c7c0'), 4 => array('campaignid' => $this->aIds['campaigns'][5], 'md5' => '9932d540cb5b63f264b3f7391577fe93'), 5 => array('campaignid' => $this->aIds['campaigns'][6], 'md5' => 'c6ae927806e0a61f9cd269659a225435')), 'utf8_utf8' => array(0 => array('campaignid' => $this->aIds['campaigns'][1], 'md5' => '1698982c38317c8c42ae4772bbee8f44'), 1 => array('campaignid' => $this->aIds['campaigns'][2], 'md5' => '317f56003783a2a9284306eb57fe8146'), 2 => array('campaignid' => $this->aIds['campaigns'][3], 'md5' => '8c8755d8f519c0245717475757d043f7'), 3 => array('campaignid' => $this->aIds['campaigns'][4], 'md5' => '7269db488f9672cca26d93105a9a2559'), 4 => array('campaignid' => $this->aIds['campaigns'][5], 'md5' => '19397ed80befa5539761afed23c4c27a'), 5 => array('campaignid' => $this->aIds['campaigns'][6], 'md5' => 'a7d508c6c8a494c80e680033cecbc76d')));
     $tblCampaigns = $this->oDbh->quoteIdentifier($this->getPrefix() . 'campaigns', true);
     // Check that the campaign names are correctly created:
     $query = "SELECT campaignid, campaignname FROM {$tblCampaigns}";
     $result = $this->oDbh->queryAll($query);
     foreach (array_keys($result) as $k) {
         $result[$k]['md5'] = md5($result[$k]['campaignname']);
         unset($result[$k]['campaignname']);
     }
     $this->assertIdentical($result, $expected['latin1_utf8']);
     // Upgrade the dataset and ensure that the upgraded campaign names were upgraded correctly:
     $this->upgradeToVersion(544);
     // Fields requiring encoding changes should now be correct
     $query = "SELECT campaignid, campaignname FROM {$tblCampaigns}";
     $result = $this->oDbh->queryAll($query);
     foreach (array_keys($result) as $k) {
         $result[$k]['md5'] = md5($result[$k]['campaignname']);
         unset($result[$k]['campaignname']);
     }
     $this->assertIdentical($result, $expected['utf8_utf8']);
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:50,代码来源:EncodingMigration.mig.test.php

示例2: singleton


//.........这里部分代码省略.........
     }
     if (!(count($aConnections) > 0) || !in_array($dsnMd5, $aConnections)) {
         // Prepare options for a new database connection
         $aOptions = array();
         // Sequence column name
         $aOptions['seqcol_name'] = 'id';
         // Set the index name format
         $aOptions['idxname_format'] = '%s';
         // Use 4 decimal places in DECIMAL nativetypes
         $aOptions['decimal_places'] = 4;
         // Set the portability options
         $aOptions['portability'] = OA_DB_MDB2_DEFAULT_OPTIONS;
         // Set the default table type for MySQL, if appropriate
         if (strcasecmp($databaseType, 'mysql') === 0) {
             if (!empty($aConf['table']['type'])) {
                 $aOptions['default_table_type'] = $aConf['table']['type'];
                 // Enable transaction support when using InnoDB tables
                 if (strcasecmp($aOptions['default_table_type'], 'innodb') === 0) {
                     // Enable transaction support
                     $aOptions['use_transactions'] = true;
                 }
             }
         } elseif (strcasecmp($databaseType, 'pgsql') === 0) {
             $aOptions['quote_identifier'] = true;
         }
         // Add default charset - custom OpenX
         if (defined('OA_DB_MDB2_DEFAULT_CHARSET')) {
             $aOptions['default_charset'] = OA_DB_MDB2_DEFAULT_CHARSET;
         } else {
             $aOptions['default_charset'] = 'utf8';
         }
         // this will log select queries to a var/sql.log
         // currently used for analysis purposes
         if (isset($aConf['debug']['logSQL']) && $aConf['debug']['logSQL']) {
             $aOptions['log_statements'] = explode('|', $aConf['debug']['logSQL']);
             $aOptions['debug'] = true;
             $aOptions['debug_handler'] = 'logSQL';
         }
         $aOptions += OA_DB::getDatatypeMapOptions();
         // Is this a MySQL database connection?
         if (strcasecmp($databaseType, 'mysql') === 0) {
             // Should this connection happen over SSL?
             if (@$aDriverOptions['ssl']) {
                 $aOptions['ssl'] = true;
             }
         }
         // Create the new database connection
         OA::disableErrorHandling();
         $oDbh = MDB2::singleton($dsn, $aOptions);
         OA::enableErrorHandling();
         if (PEAR::isError($oDbh)) {
             return $oDbh;
         }
         // Is this a MySQL database connection?
         if (strcasecmp($databaseType, 'mysql') === 0) {
             $client_flags = 0;
             // Should this connection happen over SSL?
             if (@$aDriverOptions['ssl']) {
                 $client_flags = $client_flags | MYSQL_CLIENT_SSL;
             }
             // Should this connection use compression?
             if (@$aDriverOptions['compress']) {
                 $client_flags = $client_flags | MYSQL_CLIENT_COMPRESS;
             }
             // Are there any MySQL connection flags to set?
             if ($client_flags != 0) {
                 $oDbh->dsn['client_flags'] = $client_flags;
             }
         }
         OA::disableErrorHandling();
         $success = $oDbh->connect();
         OA::enableErrorHandling();
         if (PEAR::isError($success)) {
             return $success;
         }
         // Set charset if needed
         $success = OA_DB::setCharset($oDbh);
         if (PEAR::isError($success)) {
             return $success;
         }
         // Set schema if needed
         $success = OA_DB::setSchema($oDbh);
         if (PEAR::isError($success)) {
             return $success;
         }
         // Set the fetchmode to be use used
         $oDbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
         // Load modules that are likely to be needed
         $oDbh->loadModule('Extended');
         $oDbh->loadModule('Datatype');
         $oDbh->loadModule('Manager');
         // Store the database connection
         $GLOBALS['_OA']['CONNECTIONS'][$dsnMd5] = $oDbh;
         // Set MySQL 4 compatibility if needed
         if (strcasecmp($databaseType, 'mysql') === 0 && !empty($aConf['database']['mysql4_compatibility'])) {
             $oDbh->exec("SET SESSION sql_mode='MYSQL40'");
         }
     }
     return $GLOBALS['_OA']['CONNECTIONS'][$dsnMd5];
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:101,代码来源:DB.php


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