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


PHP Zend_Db_Adapter_Abstract::exec方法代码示例

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


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

示例1: buildSearchIndex

    /**
     * Rebuild shopware search index
     * Loop through all tables / columns that should be considered in search
     * Write keywords to desired table
     * @throws Enlight_Exception
     */
    public function buildSearchIndex()
    {
        // Set time of last cache rebuild
        $sql = '
            SET @parent = (SELECT id FROM s_core_config_elements WHERE name = \'fuzzysearchlastupdate\');
            DELETE FROM `s_core_config_values` WHERE element_id = @parent;
            INSERT INTO `s_core_config_values` (`element_id`, `shop_id`, `value`) VALUES
            (@parent, 1, CONCAT(\'s:\', LENGTH(NOW()), \':"\', NOW(), \'";\'));
        ';
        $this->database->exec($sql);

        // Truncate search index table
        $this->database->query('TRUNCATE TABLE `s_search_index`');

        // Get a list of all tables and columns in this tables that should be processed by search
        /**
         * Example return:
         * tableID | table      | where | referenz_table | fieldIDs | fields            | foreign_key
         * 1       | s_articles | NULL  | NULL           | 3,4      | name, keywords    | NULL
         * 2       | s_categories | NULL | s_articles_categories | 1,2 | metakeywords, description | categoryID
         */
        $tables = $this->getSearchInvolvedTables();

        if (!empty($tables)) {
            foreach ($tables as $table) {
                // Set primary key
                $table['elementID'] = empty($table['foreign_key']) && $table['table'] != 's_articles' ? 'articleID' : 'id';
                // Build sql query to fetch values from this table
                $sql = 'SELECT ' . $table['elementID'] . ' as id, ' . $table['fields'] . ' FROM ' . $table['table'];
                // If any where condition is set, add to query
                if (!empty($table['where'])) $sql .= 'WHERE ' . $table['where'];

                // Get all fields & values from current table

                $getTableKeywords = $this->database->fetchAll($sql);

                // If no result, return
                if (empty($getTableKeywords)) {
                    continue;
                }

                // Build array from columns fieldIDs and fields
                $fields = array_combine(explode(', ', $table["fieldIDs"]), explode(', ', $table["fields"]));
                $keywords = array();
                $sql_index = array();

                // Go through every row of result
                foreach ($getTableKeywords as $currentRow => $row) {
                    // Go through every column of result
                    foreach ($fields as $fieldID => $field) {
                        // Split string from column into keywords
                        $field_keywords = $this->getKeywordsFromString($row[$field]);
                        if (empty($field_keywords)) {
                            continue;
                        }

                        foreach ($field_keywords as &$keyword) {
                            $keyword = $this->database->quote($keyword);
                            $keywords[] = $keyword;
                        }

                        // SQL-queries to fill s_search_index
                        $sql_index[] = 'SELECT sk.id as keywordID, ' . $row['id'] . ' as elementID, ' . $fieldID . ' as fieldID '
                            . 'FROM s_search_keywords sk '
                            . 'WHERE sk.keyword IN (' . implode(', ', $field_keywords) . ')';
                    }

                    // If no new keywords were found, proceed with next table
                    if (empty($keywords)) {
                        continue;
                    }

                    // If last row or more then 5000 keywords fetched, write results to index
                    if ($currentRow == count($getTableKeywords) - 1 || count($keywords) > 5000) {
                        $keywords = array_unique($keywords); // Remove duplicates
                        $sql_keywords = 'INSERT IGNORE INTO `s_search_keywords` (`keyword`) VALUES';
                        $sql_keywords .= ' (' . implode('), (', $keywords) . ')';

                        // Insert Keywords
                        try {
                            $this->database->query($sql_keywords);
                        } catch (PDOException $e) {
                            throw new Enlight_Exception($e->getMessage());
                        }

                        $keywords = array();

                        // Update index
                        try {
                            $sql_index = implode("\n\nUNION ALL\n\n", $sql_index);
                            $sql_index = "INSERT DELAYED IGNORE INTO s_search_index (keywordID, elementID, fieldID)\n\n" . $sql_index;
                            $this->database->query($sql_index);
                            $sql_index = array();
                        } catch (PDOException $e) {
//.........这里部分代码省略.........
开发者ID:nhp,项目名称:shopware-4,代码行数:101,代码来源:Default.php

示例2: __construct

 /**
  * Constructor
  */
 protected function __construct($blnWithDbh = true, Zend_Config_Xml &$sysConfig, Zend_Config_Xml &$modConfig, Zend_Config_Xml &$webConfig)
 {
     /**
      * set sys config object
      */
     $this->sysConfig = $sysConfig;
     /**
      * set modules config object
      */
     $this->modConfig = $modConfig;
     /**
      * set website config object
      */
     $this->webConfig = $webConfig;
     /**
      * initialize Zend_Log
      */
     $this->logger = new Zend_Log();
     /**
      * create logfile extension for file writer
      */
     if (isset($_SESSION["sesUserName"]) && isset($_SERVER['REMOTE_ADDR'])) {
         $strLogFileExtension = $_SESSION["sesUserName"] . '_' . $_SERVER['REMOTE_ADDR'];
     } else {
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $strLogFileExtension = $_SERVER['REMOTE_ADDR'];
         } else {
             $strLogFileExtension = 'local';
         }
     }
     /**
      * create log file writer
      */
     $writer = new Zend_Log_Writer_Stream(GLOBAL_ROOT_PATH . $this->sysConfig->logger->path . 'log_' . date('Ymd') . '_' . $strLogFileExtension . '.log');
     $this->logger->addWriter($writer);
     /**
      * set log priority
      */
     $filter = new Zend_Log_Filter_Priority((int) $this->sysConfig->logger->priority);
     $this->logger->addFilter($filter);
     if ($blnWithDbh == true) {
         /**
          * initialize the ZEND DB Connection
          * do lazy connection binding, so db connection will be established on first use with dbh->getConnection()
          */
         try {
             $pdoParams = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true);
             $dbhParameters = array('host' => $this->sysConfig->database->params->host, 'username' => $this->sysConfig->database->params->username, 'password' => $this->sysConfig->database->params->password, 'dbname' => $this->sysConfig->database->params->dbname, 'driver_options' => $pdoParams);
             $this->dbh = Zend_Db::factory($this->sysConfig->database->adapter, $dbhParameters);
             $this->dbh->getConnection();
             $this->dbh->exec('SET CHARACTER SET ' . $this->sysConfig->encoding->db);
             Zend_Db_Table::setDefaultAdapter($this->dbh);
         } catch (Zend_Db_Adapter_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         } catch (Zend_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         }
         //$this->initGuiTexts();
     }
 }
开发者ID:BGCX261,项目名称:zoolu-svn-to-git,代码行数:67,代码来源:core.class.php

示例3: tearDown

 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     $this->db->exec('DROP TABLE IF EXISTS s_crontab ');
 }
开发者ID:nvdnkpr,项目名称:Enlight,代码行数:8,代码来源:CronManagerTest.php

示例4: __construct


//.........这里部分代码省略.........
                 $this->logger->info('SESSION');
                 $this->intLanguageId = $this->objCoreSession->languageId;
                 $this->strLanguageCode = $this->objCoreSession->languageCode;
             } else {
                 $this->logger->info('DEFAULT');
                 $this->blnIsDefaultLanguage = true;
                 $this->intLanguageId = $this->sysConfig->languages->default->id;
                 $this->strLanguageCode = $this->sysConfig->languages->default->code;
             }
         }
     } else {
         if (isset($_SERVER['REQUEST_URI']) && preg_match('/^\\/[a-zA-Z\\-]{2,5}\\//', $_SERVER['REQUEST_URI'])) {
             $this->logger->info('URI');
             preg_match('/^\\/[a-zA-Z\\-]{2,5}\\//', $_SERVER['REQUEST_URI'], $arrMatches);
             $this->strLanguageCode = trim($arrMatches[0], '/');
             foreach ($this->config->languages->language->toArray() as $arrLanguage) {
                 if (array_key_exists('code', $arrLanguage) && $arrLanguage['code'] == strtolower($this->strLanguageCode)) {
                     $this->intLanguageId = $arrLanguage['id'];
                     break;
                 }
             }
             if ($this->intLanguageId == null) {
                 if (isset($this->objCoreSession->languageId)) {
                     $this->logger->info('SESSION');
                     $this->intLanguageId = $this->objCoreSession->languageId;
                     $this->strLanguageCode = $this->objCoreSession->languageCode;
                 } else {
                     $this->logger->info('DEFAULT');
                     $this->blnIsDefaultLanguage = true;
                     $this->intLanguageId = $this->sysConfig->languages->default->id;
                     $this->strLanguageCode = $this->sysConfig->languages->default->code;
                 }
             }
         } else {
             if (isset($this->objCoreSession->languageId)) {
                 $this->logger->info('SESSION');
                 $this->intLanguageId = $this->objCoreSession->languageId;
                 $this->strLanguageCode = $this->objCoreSession->languageCode;
             } else {
                 $this->logger->info('DEFAULT');
                 $this->blnIsDefaultLanguage = true;
                 $this->intLanguageId = $this->sysConfig->languages->default->id;
                 $this->strLanguageCode = $this->sysConfig->languages->default->code;
             }
         }
     }
     /**
      * set up zoolu translate obj
      */
     $this->intZooluLanguageId = Zend_Auth::getInstance()->hasIdentity() ? Zend_Auth::getInstance()->getIdentity()->languageId : $this->intLanguageId;
     $this->strZooluLanguageCode = Zend_Auth::getInstance()->hasIdentity() ? Zend_Auth::getInstance()->getIdentity()->languageCode : $this->strLanguageCode;
     if (file_exists(GLOBAL_ROOT_PATH . 'application/zoolu/language/zoolu-' . $this->strZooluLanguageCode . '.mo')) {
         $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH . 'application/zoolu/language/zoolu-' . $this->strZooluLanguageCode . '.mo');
     } else {
         $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH . 'application/zoolu/language/zoolu-' . $this->zooConfig->languages->default->code . '.mo');
     }
     // update session language
     $this->updateSessionLanguage();
     if ($blnWithDbh == true) {
         /**
          * initialize the ZEND DB Connection
          * do lazy connection binding, so db connection will be established on first use with dbh->getConnection()
          */
         try {
             $pdoParams = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true);
             $dbhParameters = array('host' => $this->sysConfig->database->params->host, 'username' => $this->sysConfig->database->params->username, 'password' => $this->sysConfig->database->params->password, 'dbname' => $this->sysConfig->database->params->dbname, 'driver_options' => $pdoParams);
             $this->dbh = Zend_Db::factory($this->sysConfig->database->adapter, $dbhParameters);
             if ($this->sysConfig->logger->priority == Zend_Log::DEBUG) {
                 $this->dbh->getProfiler()->setEnabled(true);
             }
             $this->dbh->getConnection();
             $this->dbh->exec('SET CHARACTER SET ' . $this->sysConfig->encoding->db);
             Zend_Db_Table::setDefaultAdapter($this->dbh);
             /**
              * using a default metadata cache for all table objects
              *
              * set up the cache
              */
             $arrFrontendOptions = array('automatic_serialization' => true);
             /**
              * memcache server configuration
              */
             $arrServer = array('host' => Zend_Cache_Backend_Memcached::DEFAULT_HOST, 'port' => Zend_Cache_Backend_Memcached::DEFAULT_PORT, 'persistent' => Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT);
             $arrBackendOptions = array('cache_dir' => GLOBAL_ROOT_PATH . $this->sysConfig->path->cache->tables);
             $objCache = Zend_Cache::factory('Core', 'File', $arrFrontendOptions, $arrBackendOptions);
             /**
              * set the cache to be used with all table objects
              */
             Zend_Db_Table_Abstract::setDefaultMetadataCache($objCache);
         } catch (Zend_Db_Adapter_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         } catch (Zend_Exception $exc) {
             $this->logger->err($exc);
             header('Location: http://' . $this->sysConfig->hostname);
             die;
         }
     }
 }
开发者ID:BGCX261,项目名称:zoolu-svn-to-git,代码行数:101,代码来源:core.class.php


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