【发布时间】:2014-04-25 08:53:44
【问题描述】:
我在 PHP Sqlsrv 调用存储过程时遇到了这个奇怪的问题。有时它返回结果,有时不返回。用netbean php调试时,弹出Socket异常。当浏览器发出请求时,连接被重置并且不返回任何错误。
我正在使用codeigniter的sqlsrv库
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));
编辑: 好的,这越来越奇怪了,如果我在 $result 之后添加这一行,那么它在大部分时间都有效。 log_message("错误", print_r($result,true));
编辑 2: 好的,只是与将消息记录到文件中有关。像这样也可以。似乎与输出缓冲有关? log_message("error", print_r("abc123",true));
编辑 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
【问题讨论】:
-
在您的 config->database.php 中,您的数据库配置是否有
$db['default']['cache_on'] = FALSE;?编辑:也试试这个 -$db['default']['pconnect'] = FALSE; -
是的,它已经是假的了。 'cache_on' => 假,
-
那个 pconnect 也已经存在了。我刚刚在问题中添加了我的配置。
标签: php sql-server codeigniter