duanlu1793
2012-12-03 16:41
浏览 106
已采纳

Yii,SQL Server查询错误

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 ?

图片转代码服务由CSDN问答提供 功能建议

使用pdo_sqlsrv驱动程序(PHP 5.4)使用SQL Server

In 我的数据库我有 varbinary 类型和大小为7584的列。

当我尝试从此列获取值时,我收到此错误

 第8836行的G:\ .. \ .. \ .. \ framework \ yiilite.php中的sql_display_size无效
   
 
 

这是 查询:

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

在这种情况下,我得到了我需要的那个大小。 它在普通的php查询(不是PDO)和SQL Server Management Studio中工作。

当我在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(); 
   
 
 

我明白了:

SQLSTATE [IMSSP]:查询的活动结果不包含任何字段。

我认为我构建了一个 我的问题是,如何在Yii中运行这样的查询?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzhang8475 2013-02-03 15:33
    已采纳

    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.

    打赏 评论
  • dongsong4418 2012-12-21 08:54

    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.

    打赏 评论

相关推荐 更多相似问题