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


PHP xPDOQuery::toSql方法代码示例

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


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

示例1: run

 /**
  * Main method for query processing and fetching rows
  * It can return string with SQL query, array or raw rows or processed HTML chunks
  *
  * @return array|bool|string
  */
 public function run()
 {
     $this->makeQuery();
     $this->addTVFilters();
     $this->addTVs();
     $this->addJoins();
     $this->addGrouping();
     $this->addSelects();
     $this->addWhere();
     $this->addSort();
     $this->prepareQuery();
     $output = '';
     if (strtolower($this->config['return']) == 'sql') {
         $this->addTime('Returning raw sql query');
         $output = $this->query->toSql();
     } else {
         $this->modx->exec('SET SQL_BIG_SELECTS = 1');
         $this->addTime('SQL prepared <small>"' . $this->query->toSql() . '"</small>');
         $tstart = microtime(true);
         if ($this->query->stmt->execute()) {
             $this->modx->queryTime += microtime(true) - $tstart;
             $this->modx->executedQueries++;
             $this->addTime('SQL executed', microtime(true) - $tstart);
             $this->setTotal();
             $rows = $this->query->stmt->fetchAll(PDO::FETCH_ASSOC);
             $this->addTime('Rows fetched');
             $rows = $this->checkPermissions($rows);
             $this->count = count($rows);
             if (strtolower($this->config['return']) == 'ids') {
                 $ids = array();
                 foreach ($rows as $row) {
                     $ids[] = $row[$this->pk];
                 }
                 $output = implode(',', $ids);
             } elseif (strtolower($this->config['return']) == 'data') {
                 $rows = $this->prepareRows($rows);
                 $this->addTime('Returning raw data');
                 $output =& $rows;
             } elseif (strtolower($this->config['return']) == 'json') {
                 $rows = $this->prepareRows($rows);
                 $this->addTime('Returning raw data as JSON string');
                 $output = $this->modx->toJSON($rows);
             } elseif (strtolower($this->config['return']) == 'serialize') {
                 $rows = $this->prepareRows($rows);
                 $this->addTime('Returning raw data as serialized string');
                 $output = serialize($rows);
             } else {
                 $rows = $this->prepareRows($rows);
                 $time = microtime(true);
                 foreach ($rows as $row) {
                     if (!empty($this->config['additionalPlaceholders'])) {
                         $row = array_merge($this->config['additionalPlaceholders'], $row);
                     }
                     $row['idx'] = $this->idx++;
                     // Add placeholder [[+link]] if specified
                     if (!empty($this->config['useWeblinkUrl'])) {
                         if (!isset($row['context_key'])) {
                             $row['context_key'] = '';
                         }
                         if (isset($row['class_key']) && $row['class_key'] == 'modWebLink') {
                             $row['link'] = isset($row['content']) && is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), '', '', $this->config['scheme']) : (isset($row['content']) ? $row['content'] : '');
                         } else {
                             $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->config['scheme']);
                         }
                     } else {
                         $row['link'] = '';
                     }
                     $tpl = $this->defineChunk($row);
                     if (empty($tpl)) {
                         $output[] = '<pre>' . $this->getChunk('', $row) . '</pre>';
                     } else {
                         $output[] = $this->getChunk($tpl, $row, $this->config['fastMode']);
                     }
                 }
                 $this->addTime('Returning processed chunks', microtime(true) - $time);
                 if (!empty($this->config['toSeparatePlaceholders'])) {
                     $this->modx->setPlaceholders($output, $this->config['toSeparatePlaceholders']);
                     $output = '';
                 } elseif (!empty($output)) {
                     $output = implode($this->config['outputSeparator'], $output);
                 }
             }
         } else {
             $this->modx->log(modX::LOG_LEVEL_INFO, '[pdoTools] ' . $this->query->toSql());
             $errors = $this->query->stmt->errorInfo();
             $this->modx->log(modX::LOG_LEVEL_ERROR, '[pdoTools] Error ' . $errors[0] . ': ' . $errors[2]);
             $this->addTime('Could not process query, error #' . $errors[1] . ': ' . $errors[2]);
         }
     }
     return $output;
 }
开发者ID:WhisperingTree,项目名称:blog,代码行数:97,代码来源:pdofetch.class.php

示例2: prepareQueryAfterCount

 public function prepareQueryAfterCount(xPDOQuery $c)
 {
     $c->prepare();
     $this->modx->log(modX::LOG_LEVEL_ERROR, $c->toSql());
     return $c;
 }
开发者ID:sergant210,项目名称:AdminTools,代码行数:6,代码来源:getlist.class.php


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