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


PHP DbHelper::isDatabaseConnectionUTF8方法代码示例

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


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

示例1: tableInsertBatch

 /**
  * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs,
  * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
  *
  * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
  * @param array $fields array of unquoted field names
  * @param array $values array of data to be inserted
  * @param bool $throwException Whether to throw an exception that was caught while trying
  *                                LOAD DATA INFILE, or not.
  * @throws Exception
  * @return bool  True if the bulk LOAD was used, false if we fallback to plain INSERTs
  */
 public static function tableInsertBatch($tableName, $fields, $values, $throwException = false)
 {
     $filePath = PIWIK_USER_PATH . '/tmp/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv';
     $filePath = SettingsPiwik::rewriteTmpPathWithInstanceId($filePath);
     $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile'];
     if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) {
         try {
             $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) {
                 return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str);
             }, 'eol' => "\r\n", 'null' => 'NULL');
             // hack for charset mismatch
             if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) {
                 $fileSpec['charset'] = 'latin1';
             }
             self::createCSVFile($filePath, $fileSpec, $values);
             if (!is_readable($filePath)) {
                 throw new Exception("File {$filePath} could not be read.");
             }
             $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec);
             if ($rc) {
                 unlink($filePath);
                 return true;
             }
         } catch (Exception $e) {
             Log::info("LOAD DATA INFILE failed or not supported, falling back to normal INSERTs... Error was: %s", $e->getMessage());
             if ($throwException) {
                 throw $e;
             }
         }
     }
     // if all else fails, fallback to a series of INSERTs
     @unlink($filePath);
     self::tableInsertBatchIterate($tableName, $fields, $values);
     return false;
 }
开发者ID:brienomatty,项目名称:elmsln,代码行数:47,代码来源:BatchInsert.php

示例2: tableInsertBatch

 /**
  * Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs,
  * as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
  *
  * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
  * @param array $fields array of unquoted field names
  * @param array $values array of data to be inserted
  * @param bool $throwException Whether to throw an exception that was caught while trying
  *                                LOAD DATA INFILE, or not.
  * @throws Exception
  * @return bool  True if the bulk LOAD was used, false if we fallback to plain INSERTs
  */
 public static function tableInsertBatch($tableName, $fields, $values, $throwException = false)
 {
     $filePath = StaticContainer::get('path.tmp') . '/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv';
     $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile'];
     if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) {
         try {
             $fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) {
                 return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str);
             }, 'eol' => "\r\n", 'null' => 'NULL');
             // hack for charset mismatch
             if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) {
                 $fileSpec['charset'] = 'latin1';
             }
             self::createCSVFile($filePath, $fileSpec, $values);
             if (!is_readable($filePath)) {
                 throw new Exception("File {$filePath} could not be read.");
             }
             $rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec);
             if ($rc) {
                 unlink($filePath);
                 return true;
             }
         } catch (Exception $e) {
             if ($throwException) {
                 throw $e;
             }
         }
     }
     // if all else fails, fallback to a series of INSERTs
     @unlink($filePath);
     self::tableInsertBatchIterate($tableName, $fields, $values);
     return false;
 }
开发者ID:CaptainSharf,项目名称:SSAD_Project,代码行数:45,代码来源:BatchInsert.php

示例3: createConfigFile

 /**
  * Write configuration file from session-store
  */
 private function createConfigFile($dbInfos)
 {
     $config = Config::getInstance();
     // make sure DB sessions are used if the filesystem is NFS
     if (Filesystem::checkIfFileSystemIsNFS()) {
         $config->General['session_save_handler'] = 'dbtable';
     }
     if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) {
         $config->General['proxy_client_headers'] = $headers;
     }
     if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) {
         $config->General['proxy_host_headers'] = $headers;
     }
     if (Common::getRequestVar('clientProtocol', 'http', 'string') == 'https') {
         $protocol = 'https';
     } else {
         $protocol = ProxyHeaders::getProtocolInformation();
     }
     if (!empty($protocol) && !\Piwik\ProxyHttp::isHttps()) {
         $config->General['assume_secure_protocol'] = '1';
     }
     $config->General['salt'] = Common::generateUniqId();
     $config->General['installation_in_progress'] = 1;
     $config->database = $dbInfos;
     if (!DbHelper::isDatabaseConnectionUTF8()) {
         $config->database['charset'] = 'utf8';
     }
     $config->forceSave();
 }
开发者ID:brienomatty,项目名称:elmsln,代码行数:32,代码来源:Controller.php

示例4: databaseCheck

 /**
  * Installation Step 4: Database Check
  */
 function databaseCheck()
 {
     $this->checkPreviousStepIsValid(__FUNCTION__);
     $view = new View('@Installation/databaseCheck', $this->getInstallationSteps(), __FUNCTION__);
     $error = false;
     $this->skipThisStep(__FUNCTION__);
     if (isset($this->session->databaseVersionOk) && $this->session->databaseVersionOk === true) {
         $view->databaseVersionOk = true;
     } else {
         $error = true;
     }
     if (isset($this->session->databaseCreated) && $this->session->databaseCreated === true) {
         $dbInfos = $this->session->db_infos;
         $view->databaseName = $dbInfos['dbname'];
         $view->databaseCreated = true;
     } else {
         $error = true;
     }
     $this->createDbFromSessionInformation();
     $db = Db::get();
     try {
         $db->checkClientVersion();
     } catch (Exception $e) {
         $view->clientVersionWarning = $e->getMessage();
         $error = true;
     }
     if (!DbHelper::isDatabaseConnectionUTF8()) {
         $dbInfos = $this->session->db_infos;
         $dbInfos['charset'] = 'utf8';
         $this->session->db_infos = $dbInfos;
     }
     $view->showNextStep = true;
     $this->session->currentStepDone = __FUNCTION__;
     if ($error === false) {
         $this->redirectToNextStep(__FUNCTION__);
     }
     return $view->render();
 }
开发者ID:KiwiJuicer,项目名称:handball-dachau,代码行数:41,代码来源:Controller.php

示例5: createConfigFile

 /**
  * Write configuration file from session-store
  */
 private function createConfigFile($dbInfos)
 {
     $config = Config::getInstance();
     // make sure DB sessions are used if the filesystem is NFS
     if (Filesystem::checkIfFileSystemIsNFS()) {
         $config->General['session_save_handler'] = 'dbtable';
     }
     if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) {
         $config->General['proxy_client_headers'] = $headers;
     }
     if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) {
         $config->General['proxy_host_headers'] = $headers;
     }
     if (Common::getRequestVar('clientProtocol', 'http', 'string') == 'https') {
         $protocol = 'https';
     } else {
         $protocol = ProxyHeaders::getProtocolInformation();
     }
     if (!empty($protocol) && !\Piwik\ProxyHttp::isHttps()) {
         $config->General['assume_secure_protocol'] = '1';
     }
     $config->General['salt'] = Common::generateUniqId();
     $config->General['installation_in_progress'] = 1;
     $config->database = $dbInfos;
     if (!DbHelper::isDatabaseConnectionUTF8()) {
         $config->database['charset'] = 'utf8';
     }
     # Improved Security with IBM Bluemix
     # With SSL ALWAYS available for all Bluemix apps, let's require all requests
     # to be made over SSL (https) so that data is NOT sent in the clear.
     # Non-ssl requests will trigger a
     #    Error: Form security failed.
     #    Please reload the form and check that your cookies are enabled
     # Reference: http://piwik.org/faq/how-to/faq_91/
     # Reference: https://developer.ibm.com/answers/questions/8312/how-do-i-enable-tlsssl-for-my-bluemix-application/
     $config->General['assume_secure_protocol'] = 1;
     $config->General['force_ssl'] = 1;
     # Setup proxy_client_headers to accurately detect GeoIPs of visiting clients
     $config->General['proxy_client_headers'] = array("HTTP_X_CLIENT_IP", "HTTP_X_FORWARDED_FOR", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP");
     $config->General['proxy_host_headers'] = "HTTP_X_FORWARDED_HOST";
     # Implement some default settings that optimize performance
     $config->General['enabled_periods_UI'] = "day,week,month,year";
     $config->General['enabled_periods_API'] = "day,week,month,year";
     $config->General['action_category_level_limit'] = 3;
     $config->General['show_multisites_sparklines'] = 0;
     $config->General['anonymous_user_enable_use_segments_API'] = 0;
     $config->General['browser_archiving_disabled_enforce'] = 1;
     $config->General['enable_create_realtime_segments'] = 0;
     $config->General['enable_segment_suggested_values'] = 0;
     $config->General['adding_segment_requires_access'] = "superuser";
     $config->General['allow_adding_segments_for_all_websites'] = 0;
     $config->General['datatable_row_limits'] = "5,10,25,50";
     $config->General['enable_browser_archiving_triggering'] = 0;
     $config->General['multisites_refresh_after_seconds'] = 0;
     $config->General['enable_delete_old_data_settings_admin'] = 0;
     $config->General['enable_auto_update'] = 0;
     $config->Debug['enable_measure_piwik_usage_in_idsite'] = 0;
     $config->Debug['allow_upgrades_to_beta'] = 0;
     $config->Tracker['new_visit_api_requires_admin'] = 0;
     # Let us have this Piwik deploy track itself to get some early data and success :-)
     # $config->Debug['enable_measure_piwik_usage_in_idsite'] = 1;
     # Emailing the easy way with IBM Bluemix + the SendGrid Service
     if (isset($_ENV["REDISHOSTNAME"])) {
         $config->RedisCache['host'] = $_ENV["REDISHOSTNAME"];
         $config->RedisCache['port'] = $_ENV["REDISPORT"];
         $config->RedisCache['timeout'] = 0.0;
         $config->RedisCache['password'] = $_ENV["REDISPASSWORD"];
         $config->RedisCache['database'] = 14;
         $config->ChainedCache['backends'] = array("array", "redis");
     }
     # Let's setup the config files trusted hosts entries to handle
     # 1...N amount of user-defined IBM Bluemix app routes
     if (isset($_ENV["APPURIS"])) {
         foreach ($_ENV["APPURIS"] as $application_uri) {
             $this->addTrustedHosts("https://" . $application_uri);
         }
     }
     # Emailing the easy way with IBM Bluemix + the SendGrid Service
     if (isset($_ENV["MAILHOST"])) {
         $config->mail['transport'] = "smtp";
         $config->mail['port'] = 587;
         $config->mail['type'] = "Plain";
         $config->mail['host'] = $_ENV["MAILHOST"];
         $config->mail['username'] = $_ENV["MAILUSER"];
         $config->mail['password'] = $_ENV["MAILPASSWORD"];
     }
     $config->forceSave();
     // re-save the currently viewed language (since we saved the config file, there is now a salt which makes the
     // existing session cookie invalid)
     $this->resetLanguageCookie();
 }
开发者ID:joshisa,项目名称:piwikstart,代码行数:94,代码来源:Controller.php


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