【问题标题】:php yii The table "" for active record class "" cannot be found in the databasephp yii 在数据库中找不到活动记录类“”的表“”
【发布时间】:2012-09-09 21:37:36
【问题描述】:

我已经在 yii 中为我的 mysql 数据库创建了所有模型,效果很好。现在我想添加一个额外的数据库,即 mssql 2000。几个小时后,我已经设置了 php 和 pdo 适配器。现在我正在尝试为 mssql 中的单个表创建一个模型。它不让我。我收到以下错误。

The table "[xxx Geo Limited\$Fixed Asset]" for active record class "FixedAsset" cannot be found in the database.



    private $_model;
2301 
2302     /**
2303      * Constructor.
2304      * @param CActiveRecord $model the model instance
2305      */
2306     public function __construct($model)
2307     {
2308         $this->_model=$model;
2309 
2310         $tableName=$model->tableName();
2311         if(($table=$model->getDbConnection()->getSchema()->getTable($tableName))===null)
2312             throw new CDbException(Yii::t('yii','The table "{table}" for active record class "{class}" cannot be found in the database.',
2313                 array('{class}'=>get_class($model),'{table}'=>$tableName)));
2314         if($table->primaryKey===null)
2315         {
2316             $table->primaryKey=$model->primaryKey();
2317             if(is_string($table->primaryKey) && isset($table->columns[$table->primaryKey]))
2318                 $table->columns[$table->primaryKey]->isPrimaryKey=true;
2319             else if(is_array($table->primaryKey))
2320             {
2321                 foreach($table->primaryKey as $name)
2322                 {
2323                     if(isset($table->columns[$name]))
2324                         $table->columns[$name]->isPrimaryKey=true;

我的模型叫FixedAsset,我在mssql中的表叫[xxx Geo Limited\$Fixed Asset]

【问题讨论】:

    标签: php mysql sql-server pdo yii


    【解决方案1】:

    解决问题,指定表格时使用双引号

    public function tableName()
        {
            //exit("help");
            return "[xxxGeo Limited\$Fixed Asset]";
        }
    

    【讨论】:

      猜你喜欢
      • 2014-01-29
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多