smokeelow
smokeelow

Reputation: 95

Yii, SQL Server query error

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 ?

Upvotes: 3

Views: 1408

Answers (2)

smokeelow
smokeelow

Reputation: 95

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.

Upvotes: 1

DarkMukke
DarkMukke

Reputation: 2489

Your question was already answered on the Yii Forums :

Edit: A quick search on google provides you with tons of valid answers: The most valid answer is that the mssql PDO driver is full of bugs, you could use the ODBC driver which works less buggy.

Upvotes: 0

Related Questions