smokeelow smokeelow - 8 days ago 7
PHP Question

Yii, SQL Server query errror

Work with SQL Server, using pdo_sqlsrv driver (PHP 5.4)

In my DB I have column with

varbinary
type and size of 7584.

When I try to get value from this column I get this error

Invalid sql_display_size in G:\..\..\..\framework\yiilite.php on line 8836


Here is the query:

DECLARE @item varbinary(1728); SET @item = (SELECT Inventory FROM Character WHERE Name='CharName'); print @item;


In this case I get exactly that size that I need. It work in normal php query (not PDO) and in SQL Server Management Studio.

When I run this code in Yii:

$query = "DECLARE @item varbinary(1728); SET @item = (SELECT Inventory FROM Character WHERE Name='CharName'); print @item";
$command=Yii::app()->db->createCommand($query)->query();
$command->read();


I get this:


SQLSTATE[IMSSP]: The active result for the query contains no fields.


I think that I built a wrong query.

My question is, How to run a query like this in Yii ?

Answer

I resolved this issue. The PDO_SQLSRV driver works perfectly with MS SQL Server on Windows.

The problem was that I was trying to execute the wrong query:

$query = "DECLARE @item varbinary(1728); SET @item = (SELECT Inventory FROM Character WHERE Name='CharName'); print @item";
$command=Yii::app()->db->createCommand($query)->query();

Working query:

$query = "DECLARE @items varbinary(max);SET @items = (SELECT Inventory FROM Character WHERE Name='$id');Select @items";
            $getI = Yii::app()->db->createCommand($query)->queryScalar();

That's all.