Copied! Copy Stacktrace Search Stackoverflow Search Google Exception

Database Exceptionyii\db\Exception

SQLSTATE[HY000] [1049] Unknown database 'meizhaike'

  • 1. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Connection.php at line 624
    615616617618619620621622623624625626627628629630631632633
                         
                if ($enableProfiling) {
                    Yii::endProfile($token, __METHOD__);
                }
            } catch (\PDOException $e) {
                if ($enableProfiling) {
                    Yii::endProfile($token, __METHOD__);
                }
     
                throw new Exception($e->getMessage(), $e->errorInfo, (int) $e->getCode(), $e);
            }
        }
     
        /**
         * Closes the currently active DB connection.
         * It does nothing if the connection is already closed.
         */
        public function close()
        {
                    
  • 2. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Connection.php at line 996 yii\db\Connection::open()
    990991992993994995996997998999100010011002
                             * Returns the PDO instance for the currently active master connection.
         * This method will open the master DB connection and then return [[pdo]].
         * @return PDO the PDO instance for the currently active master connection.
         */
        public function getMasterPdo()
        {
            $this->open();
            return $this->pdo;
        }
     
        /**
         * Returns the currently active slave connection.
         * If this method is called for the first time, it will try to open a slave connection when [[enableSlaves]] is true.
                    
  • 3. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Connection.php at line 983 yii\db\Connection::getMasterPdo()
    977978979980981982983984985986987988989
                             * is available and `$fallbackToMaster` is false.
         */
        public function getSlavePdo($fallbackToMaster = true)
        {
            $db = $this->getSlave(false);
            if ($db === null) {
                return $fallbackToMaster ? $this->getMasterPdo() : null;
            }
     
            return $db->pdo;
        }
     
        /**
                    
  • 4. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Command.php at line 253 yii\db\Connection::getSlavePdo()
    247248249250251252253254255256257258259
                         
            if ($this->db->getTransaction()) {
                // master is in a transaction. use the same connection.
                $forRead = false;
            }
            if ($forRead || $forRead === null && $this->db->getSchema()->isReadQuery($sql)) {
                $pdo = $this->db->getSlavePdo();
            } else {
                $pdo = $this->db->getMasterPdo();
            }
     
            try {
                $this->pdoStatement = $pdo->prepare($sql);
                    
  • 5. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Command.php at line 1143 yii\db\Command::prepare(true)
    1137113811391140114111421143114411451146114711481149
                                            Yii::debug('Query result served from cache', 'yii\db\Command::query');
                        return $result[0];
                    }
                }
            }
     
            $this->prepare(true);
     
            try {
                $profile and Yii::beginProfile($rawSql, 'yii\db\Command::query');
     
                $this->internalExecute($rawSql);
     
                    
  • 6. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Command.php at line 399 yii\db\Command::queryInternal('fetchAll', null)
    393394395396397398399400401402403404405
                             * @return array all rows of the query result. Each array element is an array representing a row of data.
         * An empty array is returned if the query results in nothing.
         * @throws Exception execution failed
         */
        public function queryAll($fetchMode = null)
        {
            return $this->queryInternal('fetchAll', $fetchMode);
        }
     
        /**
         * Executes the SQL statement and returns the first row of the result.
         * This method is best used when only the first row of result is needed for a query.
         * @param int $fetchMode the result fetch mode. Please refer to [PHP manual](http://php.net/manual/en/pdostatement.setfetchmode.php)
                    
  • 7. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/mysql/Schema.php at line 312 yii\db\Command::queryAll()
    306307308309310311312313314315316317318
                             * @throws \Exception if DB query fails
         */
        protected function findColumns($table)
        {
            $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteTableName($table->fullName);
            try {
                $columns = $this->db->createCommand($sql)->queryAll();
            } catch (\Exception $e) {
                $previous = $e->getPrevious();
                if ($previous instanceof \PDOException && strpos($previous->getMessage(), 'SQLSTATE[42S02') !== false) {
                    // table does not exist
                    // https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html#error_er_bad_table_error
                    return false;
                    
  • 8. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/mysql/Schema.php at line 125 yii\db\mysql\Schema::findColumns(yii\db\TableSchema)
    119120121122123124125126127128129130131
                             */
        protected function loadTableSchema($name)
        {
            $table = new TableSchema();
            $this->resolveTableNames($table, $name);
     
            if ($this->findColumns($table)) {
                $this->findConstraints($table);
                return $table;
            }
     
            return null;
        }
                    
  • 9. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Schema.php at line 744 yii\db\mysql\Schema::loadTableSchema('news')
    738739740741742743744745746747748749750
                                }
            $rawName = $this->getRawTableName($name);
            if ($refresh || !isset($this->_tableMetadata[$rawName])) {
                $this->loadTableMetadataFromCache($cache, $rawName);
            }
            if (!array_key_exists($type, $this->_tableMetadata[$rawName])) {
                $this->_tableMetadata[$rawName][$type] = $this->{'loadTable' . ucfirst($type)}($rawName);
                $this->saveTableMetadataToCache($cache, $rawName);
            }
     
            return $this->_tableMetadata[$rawName][$type];
        }
     
                    
  • 10. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/Schema.php at line 194 yii\db\Schema::getTableMetadata('news', 'schema', false)
    188189190191192193194195196197198199200
                             * @param string $name table name. The table name may contain schema name if any. Do not quote the table name.
         * @param bool $refresh whether to reload the table schema even if it is found in the cache.
         * @return TableSchema|null table metadata. `null` if the named table does not exist.
         */
        public function getTableSchema($name, $refresh = false)
        {
            return $this->getTableMetadata($name, 'schema', $refresh);
        }
     
        /**
         * Returns the metadata for all tables in the database.
         * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema name.
         * @param bool $refresh whether to fetch the latest available table schemas. If this is `false`,
                    
  • 11. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/ActiveRecord.php at line 384 yii\db\Schema::getTableSchema('news')
    378379380381382383384385386387388389390
                             * @throws InvalidConfigException if the table for the AR class does not exist.
         */
        public static function getTableSchema()
        {
            $tableSchema = static::getDb()
                ->getSchema()
                ->getTableSchema(static::tableName());
     
            if ($tableSchema === null) {
                throw new InvalidConfigException('The table does not exist: ' . static::tableName());
            }
     
            return $tableSchema;
                    
  • 12. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/ActiveRecord.php at line 408 yii\db\ActiveRecord::getTableSchema()
    402403404405406407408409410411412413414
                             * Note that an array should be returned even for a table with single primary key.
         *
         * @return string[] the primary keys of the associated database table.
         */
        public static function primaryKey()
        {
            return static::getTableSchema()->primaryKey;
        }
     
        /**
         * Returns the list of all attribute names of the model.
         * The default implementation will return all column names of the table associated with this AR class.
         * @return array list of attribute names.
                    
  • 13. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/ActiveRecord.php at line 178 yii\db\ActiveRecord::primaryKey()
    172173174175176177178179180181182183184
                            protected static function findByCondition($condition)
        {
            $query = static::find();
     
            if (!ArrayHelper::isAssociative($condition)) {
                // query by primary key
                $primaryKey = static::primaryKey();
                if (isset($primaryKey[0])) {
                    $pk = $primaryKey[0];
                    if (!empty($query->join) || !empty($query->joinWith)) {
                        $pk = static::tableName() . '.' . $pk;
                    }
                    // if condition is scalar, search for a single primary key, if it is array, search for multiple primary key values
                    
  • 14. in /opt/www/meizhaike/vendor/yiisoft/yii2/db/BaseActiveRecord.php at line 112 yii\db\ActiveRecord::findByCondition(47496)
    106107108109110111112113114115116117118
                            /**
         * {@inheritdoc}
         * @return static|null ActiveRecord instance matching the condition, or `null` if nothing matches.
         */
        public static function findOne($condition)
        {
            return static::findByCondition($condition)->one();
        }
     
        /**
         * {@inheritdoc}
         * @return static[] an array of ActiveRecord instances, or an empty array if nothing matches.
         */
                    
  • 15. in /opt/www/meizhaike/common/models/News.php at line 345 yii\db\BaseActiveRecord::findOne(47496)
    339340341342343344345346347348349350351
                                if (!$news_id) {
                return false;
            } else {
     
                $news_id = intval($news_id);
                //声明的必填字段需要存在,否则无法插入、修改数据
                $model = News::findOne($news_id);
                if (!$model || $model->status == 1) {
                    return false;
                }
                $model->view_count += 1;
                $model->save();
     
                    
  • 16. in /opt/www/meizhaike/frontend/controllers/PictureController.php at line 552 – common\models\News::getNewsDetails(47496)
    546547548549550551552553554555556557558
                                }
     
            /*
             * 案例类资讯做跳转 Todo
             */
            $news = new News;
            $news_info = $news->getNewsDetails($newsId);
            $category = Category::getIdByPinyin('anli');
            $child_ids = Category::getChildrenIdsByCategoryId($category['id']);
            $child_ids[] = $category['id'];
            if(!in_array($news_info['category_id'], $child_ids)) {
                return $this->redirect(Yii::$app->params['news_domain'] . "zixun/anli-{$news_info['id']}.html");
            }
                    
  • 17. frontend\controllers\PictureController::actionPictureNewsDetail()
  • 18. in /opt/www/meizhaike/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array([frontend\controllers\PictureController, 'actionPictureNewsDetail'], [])
    515253545556575859
                                $args = $this->controller->bindActionParams($this, $params);
            Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__);
            if (Yii::$app->requestedParams === null) {
                Yii::$app->requestedParams = $args;
            }
     
            return call_user_func_array([$this->controller, $this->actionMethod], $args);
        }
    }
                    
  • 19. in /opt/www/meizhaike/vendor/yiisoft/yii2/base/Controller.php at line 157 yii\base\InlineAction::runWithParams(['news_id' => '47496'])
    151152153154155156157158159160161162163
                                }
     
            $result = null;
     
            if ($runAction && $this->beforeAction($action)) {
                // run the action
                $result = $action->runWithParams($params);
     
                $result = $this->afterAction($action, $result);
     
                // call afterAction on modules
                foreach ($modules as $module) {
                    /* @var $module Module */
                    
  • 20. in /opt/www/meizhaike/vendor/yiisoft/yii2/base/Module.php at line 528 yii\base\Controller::runAction('picture-news-detail', ['news_id' => '47496'])
    522523524525526527528529530531532533534
                                $parts = $this->createController($route);
            if (is_array($parts)) {
                /* @var $controller Controller */
                list($controller, $actionID) = $parts;
                $oldController = Yii::$app->controller;
                Yii::$app->controller = $controller;
                $result = $controller->runAction($actionID, $params);
                if ($oldController !== null) {
                    Yii::$app->controller = $oldController;
                }
     
                return $result;
            }
                    
  • 21. in /opt/www/meizhaike/vendor/yiisoft/yii2/web/Application.php at line 103 yii\base\Module::runAction('picture/picture-news-detail', ['news_id' => '47496'])
    979899100101102103104105106107108109
                                    $params = $this->catchAll;
                unset($params[0]);
            }
            try {
                Yii::debug("Route requested: '$route'", __METHOD__);
                $this->requestedRoute = $route;
                $result = $this->runAction($route, $params);
                if ($result instanceof Response) {
                    return $result;
                }
     
                $response = $this->getResponse();
                if ($result !== null) {
                    
  • 22. in /opt/www/meizhaike/vendor/yiisoft/yii2/base/Application.php at line 386 yii\web\Application::handleRequest(yii\web\Request)
    380381382383384385386387388389390391392
                            {
            try {
                $this->state = self::STATE_BEFORE_REQUEST;
                $this->trigger(self::EVENT_BEFORE_REQUEST);
     
                $this->state = self::STATE_HANDLING_REQUEST;
                $response = $this->handleRequest($this->getRequest());
     
                $this->state = self::STATE_AFTER_REQUEST;
                $this->trigger(self::EVENT_AFTER_REQUEST);
     
                $this->state = self::STATE_SENDING_RESPONSE;
                $response->send();
                    
  • 23. in /opt/www/meizhaike/frontend/web/index.php at line 17 yii\base\Application::run()
    11121314151617
                            require(__DIR__ . '/../../common/config/main.php'),
        require(__DIR__ . '/../../common/config/main-local.php'),
        require(__DIR__ . '/../config/main.php'),
        require(__DIR__ . '/../config/main-local.php')
    );
     
    (new yii\web\Application($config))->run();
                    
  • $_GET = [
        'news_id' => '47496',
    ];