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?