dsqve08622 2013-06-24 20:08
浏览 41
已采纳

Azure SQL Server和Yii Active Record

I have an SQL Database in Windows Azure and Yii app on local machine. I use PHP 5.4.9 and php_pdo_sqlsrv_54_nts.dll driver.

Main.php:

'db'=>array(
        'connectionString' => 'sqlsrv:Server=tcp:MYSERVER.database.windows.net,1433;Database=MYDB;',
        'username' => 'admin',
        'password' => 'pass',
        'charset' => 'utf8',
    ),

When I trying to connect to SQL Server Yii throws this exception:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'sys.extended_properties'.. The SQL statement executed was: SELECT t1.*, columnproperty(object_id(t1.table_schema+'.'+t1.table_name), t1.column_name, 'IsIdentity') AS IsIdentity, CONVERT(VARCHAR, t2.value) AS Comment FROM [INFORMATION_SCHEMA].[COLUMNS] AS t1 LEFT OUTER JOIN sys.extended_properties AS t2 ON t1.ORDINAL_POSITION = t2.minor_id AND object_name(t2.major_id) = t1.TABLE_NAME AND t2.class=1 AND t2.class_desc='OBJECT_OR_COLUMN' AND t2.name='MS_Description' WHERE t1.TABLE_NAME='users' AND t1.TABLE_SCHEMA='dbo'

It displays in Gii or on page with simple <?php echo User::model()->findAllByPk(1)->email;?> string.

What am I doing wrong?

UPD: User.php

class User extends CActiveRecord {
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'users';
    }

    public function rules()
    {
        return array(
            array('email, password', 'required')
        );
    }

    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'email' => 'Email'
        );
    }
}

Table users contains only id, email and password fields.

This code works!

$connection=Yii::app()->db;
$sql = "INSERT INTO users (email, password) VALUES ('regs@kamenskynik.name', 'example')";
$command=$connection->createCommand($sql);
$some = $command->execute();

How to use SQLSRV with Yii Active Record?

  • 写回答

1条回答 默认 最新

  • doushui3061 2013-06-30 19:17
    关注

    The problem is in https://github.com/yiisoft/yii/blob/master/framework/db/schema/mssql/CMssqlSchema.php#L294.

    I should write my own scheme for this app.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?