2013-06-24 136 views
0

我在本地機器上的Windows Azure和Yii應用程序中有一個SQL數據庫。我使用PHP 5.4.9和php_pdo_sqlsrv_54_nts.dll驅動程序。Azure SQL Server和Yii Active Record

Main.php:

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

當我試圖連接到SQL Server的Yii拋出此異常:

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' 

它顯示在GII或簡單<?php echo User::model()->findAllByPk(1)->email;?>字符串頁面上。

我在做什麼錯?

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' 
     ); 
    } 
} 

users只包含idemailpassword領域。

此代碼有效!

$connection=Yii::app()->db; 
$sql = "INSERT INTO users (email, password) VALUES ('[email protected]', 'example')"; 
$command=$connection->createCommand($sql); 
$some = $command->execute(); 

如何在Yii Active Record中使用SQLSRV?

+0

你的陳述失敗了? –

+0

它在錯誤信息中告訴你到底是什麼問題。嘗試使用在錯誤中生成的SQL語句,並找出它的錯誤。說它不喜歡你試圖加入的'sys.extended_properties'。我很懷疑你有一個名爲'sys.extended_properties'的表。 – Pitchinnate

+0

'<?php echo User :: model() - > findAllByPk(1) - > email;?>'例如。 – llvk

回答