doubi4814 2014-04-25 08:53
浏览 74
已采纳

PHP sqlsrv存储过程有时没有返回结果

I have this strange problem with PHP Sqlsrv calling a store procedure. Sometimes it return result, sometimes not. When debugging with netbean php, it popup Socket exception occurred. When the browser made the request, the connection get reset and does not return any error.

I am using the sqlsrv library of codeigniter

function result_object()
    {
        if (count($this->result_object) > 0)
        {
            return $this->result_object;
        }

        // In the event that query caching is on the result_id variable
        // will return FALSE since there isn't a valid SQL resource so
        // we'll simply return an empty array.
        if ($this->result_id === FALSE OR $this->num_rows() == 0)
        {
            return array();
        }

        $this->_data_seek(0);
        while ($row = $this->_fetch_object())
        {
            $this->result_object[] = $row;
        }

        return $this->result_object;
    }

function result($type = 'object')
    {
        if ($type == 'array') return $this->result_array();
        else if ($type == 'object') return $this->result_object();
        else return $this->custom_result_object($type);
    }

$result = null;
        do{
            $result = $this->result(); //error happen on this line.
              log_message("error", print_r($result,true)); // if added this line, the result is okay most of the time
            }while( sqlsrv_next_result($this->result_id));

EDIT : Okay, this is getting more strange, if I add this line after $result then it works MOST of the TIME . log_message("error", print_r($result,true));

EDIT 2 : Okay, just anything to do with logging message into the file. Such as like this will work also. Seem to do with output buffering ? log_message("error", print_r("abc123",true));

EDIT 3 :

'hostname'  => '192.168.8.165',
'username'  => 'xxx',
'password'  => 'xxx',
'database'  => 'dbname',
'dbdriver'  => 'sqlsrv',
'dbprefix'  => '',
'pconnect'  => FALSE,
'db_debug'  => TRUE,
'cache_on'  => FALSE,
'cachedir'  => '',
'char_set'  => 'utf8',
'dbcollat'  => 'utf8_unicode_ci',
'swap_pre'  => '',
'autoinit'  => TRUE,
'stricton'  => FALSE
  • 写回答

2条回答 默认 最新

  • dtrb96410 2014-04-29 03:34
    关注

    Finally, it's the CURSOR issue of the sqlsrv_driver.php , in that file, find this SQLSRV_CURSOR_STATIC and replace it with SQLSRV_CURSOR_CLIENT_BUFFERED . Now it return result without having to use that log_message("error", "abc123"); And even execute 1000 time of my SP there's no problem.

    Found solution from https://stackoverflow.com/a/16796421/660810

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?