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


PHP SqlQuery::getOrder方法代码示例

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


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

示例1: run

    public function run()
    {
        $response = new AjaxResponse();
        $profiling = Yii::app()->user->settings->get('profiling');
        try {
            $sqlQuery = new SqlQuery($this->query);
        } catch (SQPException $ex) {
            $response->addNotification('error', Yii::t('core', 'errorExecuteQuery'), $ex->getMessage());
            $this->response = $response;
            return;
        }
        if (!$this->query) {
            $this->query = $this->getDefaultQuery();
            $queries = (array) $this->query;
        } else {
            if ($profiling) {
                $cmd = $this->db->createCommand('FLUSH STATUS');
                $cmd->execute();
                $cmd = $this->db->createCommand('SET PROFILING = 1');
                $cmd->execute();
            }
            $splitter = new SqlSplitter($this->query);
            $queries = $splitter->getQueries();
        }
        if ($this->execute) {
            $queryCount = count($queries);
            $i = 1;
            foreach ($queries as $query) {
                try {
                    $sqlQuery = new SqlQuery($query);
                } catch (SQPException $ex) {
                    $response->addNotification('error', Yii::t('core', 'errorExecuteQuery'), $ex->getMessage());
                    break;
                }
                $type = $sqlQuery->getType();
                $this->table = $sqlQuery->getTable();
                $this->tables = $sqlQuery->getTables();
                $this->singleTableSelect = count($this->tables) == 1;
                // SELECT
                if ($type == "select") {
                    // Pagination
                    $pages = new Pagination();
                    $pages->route = $this->route;
                    $pageSize = $pages->setupPageSize('pageSize', 'schema.table.browse');
                    // Sorting
                    $sort = new Sort($this->db);
                    $sort->multiSort = false;
                    $sort->route = $this->route;
                    $sqlQuery->applyCalculateFoundRows();
                    $limit = $sqlQuery->getLimit();
                    $order = $sqlQuery->getOrder();
                    // Apply sort
                    if ($sort->getOrder()) {
                        $sqlQuery->applySort($sort->getOrder(), true);
                    }
                    if (isset($_REQUEST['page'])) {
                        $offset = $_REQUEST['page'] * $pageSize - $pageSize;
                        $sqlQuery->applyLimit($pageSize, $offset, true);
                    }
                    // Set pagesize from query limit
                    if ($limit && !isset($_REQUEST[$pages->pageSizeVar])) {
                        $_REQUEST[$pages->pageSizeVar] = $limit['length'];
                        $pageSize = $pages->setupPageSize('pageSize', 'schema.table.browse');
                        $offset = $limit['start'];
                    } elseif (!$limit) {
                        $offset = 0;
                        $sqlQuery->applyLimit($pageSize, $offset, true);
                    } elseif (isset($_REQUEST[$pages->pageSizeVar])) {
                        $pageSize = $pages->setupPageSize('pageSize', 'schema.table.browse');
                        $offset = 0;
                        $sqlQuery->applyLimit($pageSize, $offset, true);
                    }
                    $this->start = (int) $offset;
                } elseif ($type == "insert" || $type == "update" || $type == "delete") {
                    #predie("insert / update / delete statement");
                    $response->refresh = true;
                } elseif ($type == "show") {
                    // show create table etc.
                } elseif ($type == "explain") {
                } elseif ($type == "analyze" || $type == "optimize" || $type == "repair" || $type == "check") {
                    // Table functions
                } elseif ($type == "use") {
                    $name = $sqlQuery->getDatabase();
                    if ($queryCount == 1 && $name && $this->schema != $name) {
                        $response->redirectUrl = Yii::app()->baseUrl . '/schema/' . $name . '#sql';
                        $response->addNotification('success', Yii::t('core', 'successChangeDatabase', array('{name}' => $name)));
                    }
                } elseif ($type == "create") {
                    $response->reload = true;
                } elseif ($type == "drop") {
                    $response->reload = true;
                }
                $this->executedQueries[] = $sqlQuery->getQuery();
                $this->originalQueries[] = $sqlQuery->getOriginalQuery();
                if ($type == "select") {
                    $pages->postVars = $sort->postVars = array('query' => $sqlQuery->getOriginalQuery());
                }
                // Prepare query for execution
                $cmd = $this->db->createCommand($sqlQuery->getQuery());
                $cmd->prepare();
//.........这里部分代码省略.........
开发者ID:cebe,项目名称:chive,代码行数:101,代码来源:BrowsePage.php


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