I am using the 2.0 version of the native php driver. I think I fixed some issues with row count and calling stored procedures.
Please handle with care I’m just experimenting…
Starting from http://www.phrenzy.org/code/sqlsrv-1.1.tar.gz
sqlsrv_driver.php
- Had problems with charset, so left default settings
- Added ReturnDatesAsStrings parameter, this configuration item must be added to application/config/database.php
$db[‘default’][‘returndates_as_strings’]
function db_connect($pooling = false)
{
// Check for a UTF-8 charset being passed as CI's default 'utf8'.
$character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set;
$connection = array(
'UID' => empty($this->username) ? '' : $this->username,
'PWD' => empty($this->password) ? '' : $this->password,
'Database' => $this->database,
'ConnectionPooling' => $pooling ? 1 : 0,
/*'CharacterSet' => $character_set,*/
'ReturnDatesAsStrings'=> empty($this->returndates_as_strings) ? FALSE : $this->returndates_as_strings,
);
// If the username and password are both empty, assume this is a
// 'Windows Authentication Mode' connection.
if(empty($connection['UID']) && empty($connection['PWD'])) {
unset($connection['UID'], $connection['PWD']);
}
return sqlsrv_connect($this->hostname, $connection);
}
- Added a switch so stored procedures can be called with SQLSRV_CURSOR_FORWARD, while all other queries are called with the SQLSRV_CURSOR_STATIC. This is only for stored procedures which return a resultset (no parameter handling yet).
function _execute($sql)
{
$sql = $this->_prep_query($sql);
$options = array(
'Scrollable' => SQLSRV_CURSOR_STATIC
);
if (stripos($sql, '{call') !== FALSE)
{
$options['Scrollable'] = SQLSRV_CURSOR_FORWARD;
}
return sqlsrv_query($this->conn_id, $sql, null, $options);
}
sqlsrv_result.php
- for some reason function must return TRUE in case of stored procedures, this should return correct row count when using SQLSRV_CURSOR_STATIC for standard queries
function num_rows()
{
$num_rows= sqlsrv_num_rows($this->result_id);
return $num_rows ? $num_rows : TRUE;
}