3

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 ?

2
  • What if you just put this in your query : DECLARE @item varbinary(1728);SELECT Inventory FROM Character WHERE Name='CharName'; Commented Dec 3, 2012 at 16:46
  • I tried this and it picks me everything in the column. Error "Fatal error: Invalid sql_display_size in C:\..\framework\yiilite.php on line 8836" Commented Dec 3, 2012 at 17:07

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Lone link is considered a poor answer since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to.
yep it was poor, but if you would have checked the link i provided it is even worse that the guy answered his own question but didn't post it in here, so yeh poor answer for a poor question..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.