diff -x .svn -x '*~' -I '\* @version $Id:' -I '$Id: mssql' -urNEB branch-old/phpBB/docs/CHANGELOG.html branch-new/phpBB/docs/CHANGELOG.html
--- branch-old/phpBB/docs/CHANGELOG.html 2010-02-10 23:46:55.000000000 +0100
+++ branch-new/phpBB/docs/CHANGELOG.html 2010-02-11 00:48:00.000000000 +0100
@@ -96,6 +96,7 @@
[Fix] Honor minimum and maximum password length in generated passwords as much as we can. (Bug #13181)
[Fix] No longer return the character O in generated random strings and passwords. (Bug #57345)
[Fix] Some XHTML corrections in subsilver2. (Bug #57505)
+ [Feature] Support for Microsoft's Native SQL Server Driver for PHP (Bug #57055 - Patch by Chris Pucci at Microsoft)
1.ii. Changes since 3.0.6
diff -x .svn -x '*~' -I '\* @version $Id:' -I '$Id: mssql' -urNEB branch-old/phpBB/includes/db/db_tools.php branch-new/phpBB/includes/db/db_tools.php
--- branch-old/phpBB/includes/db/db_tools.php 2010-02-10 23:53:11.000000000 +0100
+++ branch-new/phpBB/includes/db/db_tools.php 2010-02-11 01:02:52.000000000 +0100
@@ -159,7 +159,7 @@
'VCHAR_CI' => '[varchar] (255)',
'VARBINARY' => '[varchar] (255)',
),
-
+
'mssqlnative' => array(
'INT:' => '[int]',
'BINT' => '[float]',
@@ -189,7 +189,7 @@
'VCHAR_CI' => '[varchar] (255)',
'VARBINARY' => '[varchar] (255)',
),
-
+
'oracle' => array(
'INT:' => 'number(%d)',
'BINT' => 'number(20)',
@@ -336,7 +336,7 @@
case 'mssql_odbc':
$this->sql_layer = 'mssql';
break;
-
+
case 'mssqlnative':
$this->sql_layer = 'mssqlnative';
break;
@@ -1837,7 +1837,7 @@
{
$index_array = array();
- if ($this->sql_layer == 'mssql' || $this->sql_laery == 'mssqlnative')
+ if ($this->sql_layer == 'mssql' || $this->sql_layer == 'mssqlnative')
{
$sql = "EXEC sp_statistics '$table_name'";
$result = $this->db->sql_query($sql);
diff -x .svn -x '*~' -I '\* @version $Id:' -I '$Id: mssql' -urNEB branch-old/phpBB/includes/db/mssqlnative.php branch-new/phpBB/includes/db/mssqlnative.php
--- branch-old/phpBB/includes/db/mssqlnative.php 2010-02-10 23:53:11.000000000 +0100
+++ branch-new/phpBB/includes/db/mssqlnative.php 2010-02-11 01:05:33.000000000 +0100
@@ -2,13 +2,12 @@
/**
*
* @package dbal
-* This is the MS SQL Server Native database abstraction layer.
-* PHP mssql native driver required.
-* You can download the latest version of the driver at:
-* http://www.microsoft.com/sql/technologies/php/default.mspx
-* or http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx
-* @copyright (c) 2005 phpBB Group
+* @version $Id: mssqlnative.php 10490 2010-02-11 00:05:32Z naderman $
+* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+* This is the MS SQL Server Native database abstraction layer.
+* PHP mssql native driver required.
* @author Chris Pucci
*
*/
@@ -24,73 +23,73 @@
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/**
- * Prior to version 1.1 the SQL Server Native PHP driver didn't support sqlsrv_num_rows, or cursor based seeking so we recall all rows into an array
+ * Prior to version 1.1 the SQL Server Native PHP driver didn't support sqlsrv_num_rows, or cursor based seeking so we recall all rows into an array
* and maintain our own cursor index into that array.
*/
-class result_mssqlnative
+class result_mssqlnative
{
- public function result_mssqlnative($queryresult = false)
+ public function result_mssqlnative($queryresult = false)
{
$this->m_cursor = 0;
$this->m_rows = array();
$this->m_num_fields = sqlsrv_num_fields($queryresult);
$this->m_field_meta = sqlsrv_field_metadata($queryresult);
-
- while($row = sqlsrv_fetch_array($queryresult, SQLSRV_FETCH_ASSOC))
+
+ while ($row = sqlsrv_fetch_array($queryresult, SQLSRV_FETCH_ASSOC))
{
- if($row !== null)
+ if ($row !== null)
{
- foreach($row as $k => $v)
+ foreach($row as $k => $v)
{
- if (is_object($v) && method_exists($v, 'format'))
+ if (is_object($v) && method_exists($v, 'format'))
{
$row[$k] = $v->format("Y-m-d\TH:i:s\Z");
}
}
$this->m_rows[] = $row;//read results into memory, cursors are not supported
- }
+ }
}
-
+
$this->m_row_count = count($this->m_rows);
sqlsrv_free_stmt($queryresult);
}
- private function array_to_obj($array, &$obj)
+ private function array_to_obj($array, &$obj)
{
- foreach ($array as $key => $value)
+ foreach ($array as $key => $value)
{
- if (is_array($value))
+ if (is_array($value))
{
$obj->$key = new stdClass();
array_to_obj($value, $obj->$key);
- }
- else
+ }
+ else
{
$obj->$key = $value;
}
}
return $obj;
}
-
- public function fetch($mode=SQLSRV_FETCH_BOTH, $object_class = 'stdClass')
+
+ public function fetch($mode = SQLSRV_FETCH_BOTH, $object_class = 'stdClass')
{
- if($this->m_cursor >= $this->m_row_count || $this->m_row_count == 0)
+ if ($this->m_cursor >= $this->m_row_count || $this->m_row_count == 0)
{
return false;
}
-
+
$ret = false;
$arr_num = array();
-
- if($mode == SQLSRV_FETCH_NUMERIC || $mode == SQLSRV_FETCH_BOTH)
+
+ if ($mode == SQLSRV_FETCH_NUMERIC || $mode == SQLSRV_FETCH_BOTH)
{
- foreach($this->m_rows[$this->m_cursor] as $key=>$value)
+ foreach($this->m_rows[$this->m_cursor] as $key => $value)
{
$arr_num[] = $value;
}
}
-
- switch($mode)
+
+ switch ($mode)
{
case SQLSRV_FETCH_ASSOC:
$ret = $this->m_rows[$this->m_cursor];
@@ -110,41 +109,41 @@
return $ret;
}
- public function get($pos, $fld)
+ public function get($pos, $fld)
{
return $this->m_rows[$pos][$fld];
}
- public function num_rows()
+ public function num_rows()
{
return $this->m_row_count;
}
- public function seek($iRow)
+ public function seek($iRow)
{
$this->m_cursor = min($iRow, $this->m_row_count);
}
- public function num_fields()
+ public function num_fields()
{
return $this->m_num_fields;
}
- public function field_name($nr)
+ public function field_name($nr)
{
$arr_keys = array_keys($this->m_rows[0]);
return $arr_keys[$nr];
}
- public function field_type($nr)
+ public function field_type($nr)
{
- $i=0;
+ $i = 0;
$int_type = -1;
$str_type = '';
-
- foreach($this->m_field_meta as $meta)
+
+ foreach ($this->m_field_meta as $meta)
{
- if($nr==$i)
+ if ($nr == $i)
{
$int_type = $meta['Type'];
break;
@@ -153,7 +152,7 @@
}
//http://msdn.microsoft.com/en-us/library/cc296183.aspx contains type table
- switch($int_type)
+ switch ($int_type)
{
case SQLSRV_SQLTYPE_BIGINT: $str_type = 'bigint'; break;
case SQLSRV_SQLTYPE_BINARY: $str_type = 'binary'; break;
@@ -186,7 +185,7 @@
return $str_type;
}
- public function free()
+ public function free()
{
unset($this->m_rows);
return;
@@ -200,34 +199,33 @@
{
var $m_insert_id = NULL;
var $last_query_text = '';
-
+
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
# Test for driver support, to avoid suppressed fatal error
- if (!function_exists('sqlsrv_connect'))
+ if (!function_exists('sqlsrv_connect'))
{
- die('Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx\n');
+ trigger_error('Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx\n', E_USER_ERROR);
}
-
+
//set up connection variables
$this->persistency = $persistency;
$this->user = $sqluser;
$this->dbname = $database;
$port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':';
$this->server = $sqlserver . (($port) ? $port_delimiter . $port : '');
-
+
//connect to database
- error_reporting( E_ALL );
- $this->db_connect_id = sqlsrv_connect($this->server, array('Database'=>$this->dbname,'UID'=>$this->user,'PWD'=>$sqlpassword));
-
- if($this->db_connect_id === false)
- {
- print_r('Unable to connect to database:');
- die(print_r(sqlsrv_errors(), true));
- }
+ error_reporting(E_ALL);
+ $this->db_connect_id = sqlsrv_connect($this->server, array(
+ 'Database' => $this->dbname,
+ 'UID' => $this->user,
+ 'PWD' => $sqlpassword
+ ));
+
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
@@ -302,7 +300,7 @@
{
$this->sql_report('start', $query);
}
-
+
$this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
@@ -347,29 +345,29 @@
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
$this->query_result = false;
-
- if($offset === false || $offset == 0)
+
+ if ($offset === false || $offset == 0)
{
- if (strpos($query, "SELECT") === false)
+ if (strpos($query, "SELECT") === false)
{
$query = "TOP {$total} " . $query;
- }
- else
+ }
+ else
{
- $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query);
- }
+ $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query);
+ }
}
- else
+ else
{
- $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query);
- $query = 'SELECT *
- FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3
+ $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query);
+ $query = 'SELECT *
+ FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3
FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3
WHERE line3 BETWEEN ' . ($offset+1) . ' AND ' . ($offset + $total);
}
-
+
$result = $this->sql_query($query, $cache_ttl);
-
+
return $result;
}
@@ -447,8 +445,8 @@
$id = $row[0];
@sqlsrv_free_stmt($result_id);
return $id;
- }
- else
+ }
+ else
{
return false;
}
@@ -504,10 +502,10 @@
{
$errors = @sqlsrv_errors(SQLSRV_ERR_ERRORS);
$error_message = '';
-
- if($errors != null)
+
+ if ($errors != null)
{
- foreach($errors as $error)
+ foreach ($errors as $error)
{
$error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n";
$error_message .= "code: ".$error[ 'code']."\n";
@@ -515,8 +513,8 @@
}
$this->last_error_result = $error_message;
$error = $this->last_error_result;
- }
- else
+ }
+ else
{
$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
}
@@ -588,21 +586,25 @@
break;
}
}
-
- /**
- * Utility method used to retrieve number of rows
+
+ /**
+ * Utility method used to retrieve number of rows
* Emulates mysql_num_rows
- * Used in acp_database.php -> write_data_mssqlnative()
- */
- function mssqlnative_num_rows($res){
- if($res !== false){
+ * Used in acp_database.php -> write_data_mssqlnative()
+ */
+ function mssqlnative_num_rows($res)
+ {
+ if ($res !== false)
+ {
$row = new result_mssqlnative($res);
$num_rows = $row->num_rows();
return $num_rows;
- } else {
+ }
+ else
+ {
return false;
}
- }
+ }
}
-
+
?>
\ No newline at end of file
diff -x .svn -x '*~' -I '\* @version $Id:' -I '$Id: mssql' -urNEB branch-old/phpBB/install/install_install.php branch-new/phpBB/install/install_install.php
--- branch-old/phpBB/install/install_install.php 2010-02-10 23:53:11.000000000 +0100
+++ branch-new/phpBB/install/install_install.php 2010-02-11 01:02:52.000000000 +0100
@@ -1376,7 +1376,7 @@
$sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
SET config_value = 'phpbb_captcha_gd'
WHERE config_name = 'captcha_plugin'";
-
+
$sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
SET config_value = '1'
WHERE config_name = 'captcha_gd'";