ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:database:microsoft_sql_server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
database:microsoft_sql_server [2015/11/26 21:51] – [mssqlnative] mnewnhamv5:database:microsoft_sql_server [2022/11/15 02:13] (current) – [Common Connection Problems] mnewnham
Line 1: Line 1:
 ====== Microsoft SQL Server ===== ====== Microsoft SQL Server =====
 +~~NOTOC~~
 ===== Description ===== ===== Description =====
-There are 2 supported drivers that allow connections to Microsoft SQL Server databases. The first, **mssqlnative** allows connections from Windows Clients to Microsoft SQL Server databases versions 2008 and up, and uses the Microsoft Native Client libraries. The second**mssql** allows connections from Unix based clients using the freetds libraries.+There are 2 supported drivers that allow connections to Microsoft SQL Server databases from SQL Server 2005 upwards 
 +==== mssqlnative ==== 
 +This driver, which runs on both Windows and Linux clients, allows connections to Microsoft SQL Server databases versions 2008 and up, and uses the Microsoft Native Client libraries. This driver is recommended for Windows Clients running PHP 5.3 and higherand Linux Clients running PHP 7.0 and higher, and provides the fastest PHP connection.
  
-===== Support Status ===== +More about the Microsoft SQL Server client for Linux [[https://github.com/Microsoft/msphpsql|here]] 
-This driver is actively supported by ADOdb project members+ 
 +==== mssql==== 
 +This allows connections from Unix based clients using the freetds libraries. It can be used with version 5.x of PHP 
 + 
 +More about the FreeTDS libraries [[http://www.freetds.org/|here]]
  
-==== SQL Server 2003 ==== 
-Connecting to SQL server 2003 creates a difficulty There is no support for native client connections, and the alternative method, using php_mssql.dll was removed in PHP 5.3. The only alternative is to use a generic ODBC driver that does not require the Microsoft Native Client libraries. 
 ====== mssqlnative ====== ====== mssqlnative ======
-<WRAP right box round> +<WRAP right box round 300px
-See Also: [[database:pdo#pdo_sqlsrv|PDO driver for SQL Server]]+== Specification == 
 +^Driver Name|mssqlnative| 
 +^Data Provider|mssqlnative| 
 +^Status|Active((This driver is actively supported by ADOdb project members))| 
 +^Windows|Yes| 
 +^Unix|Yes| 
 +^ADOdb V5|Yes| 
 +^ADOdb V6|Yes| 
 +== Alternatives == 
 +[[v5:database:pdo#pdo_sqlsrv|PDO driver for SQL Server]]\\ 
 +[[v5:database:odbc#odbc_mssql|ODBC driver for SQL Server]]\\ 
 +== See Also == 
 +[[v5:reference:connection:setconnectionparameter#sqlserver|setConnectionParameter()]]
 </WRAP> </WRAP>
-<WRAP left 300px box> 
  
-**This is the preferred driver for connecting to a SQL server database from Windows clients.**+**This is the preferred driver for connecting to a SQL server database from both Windows and Linux clients.**
  
-|Driver Name|mssqlnative| +The original driver was contributed by Microsoft and provides connections to SQL server databases greater than SQL Server 2003 
-|Status|Active| +  * On Windows clients, It requires PHP version 5.3 or greater, Microsoft native client software and the appropriate PHP driver.  
-|Windows|Yes| +  * On Linux clients, PHP version 7.0 and higher is required.
-|Unix|No| +
-</WRAP> +
-This driver was contributed by Microsoft and provides connections to SQL server databases greater than version 2000. It requires PHP version 5.3 or greater, Microsoft native client software and the appropriate PHP driver. +
  
 Sequences are supported in native mode in SQL Sever 2012, and emulated in earlier versions.  Sequences are supported in native mode in SQL Sever 2012, and emulated in earlier versions. 
 +--------------------------------
 +==== DateTime Fields ====
 +The default behavior for the **PHP** mssqlnative driver is to return date/time fields as a PHP [[http://php.net/manual/en/class.datetime.php|dateTime]] object, that looks like this:
 +
 +  [RequiredDate] => DateTime Object
 +  (
 +      [date] => 1996-08-01 00:00:00.000000
 +      [timezone_type] => 3
 +      [timezone] => America/Denver
 +  )
 + 
 +
 +However, in order to improve portability, the default behaviour of the **ADOdb** mssqlnative driver is to return the date as a string:
 +
 +  [RequiredDate] => 1996-08-01 00:00:00.000000
 +
 +In order to return the dateTime as an object, the following action is required:
 +<code php>
 +$db = ADONewConnection('mssqlnative');
 +$db->setConnectionParameter('ReturnDatesAsStrings',false);
 +$db->connect('SERVER\SQLEXPRESS','user','password','NORTHWND');
 +</code>
 +
 +===== Unicode Strings =====
 +You can set the character set to UTF-8 using:
 +<code php>
 +$db = ADONewConnection('mssqlnative');
 +$db->setConnectionParameter('characterSet','UTF-8');
 +$db->connect('SERVER\SQLEXPRESS','user','password','NORTHWND');
 +</code>
 +
 +===== Using Windows Authentication =====
 +To use Windows, instead of SQL Server authentication, pass NULL as the user and password as shown below
 +<code php>
 +$db = ADONewConnection('mssqlnative');
 +$db->connect('SERVER\SQLEXPRESS',NULL,NULL,'NORTHWND');
 +</code>
 +
 +===== Common Connection Problems =====
 +Recent versions of SQL Server fail to connect with an error ''Message: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate chain was issued by an authority that is not trusted.''
 +
 +This problem can be resolved by adding
 +
 +<code php>
 +$db->setConnectionParameter('TrustServerCertificate',1);
 +</code>
 +
 +before issuing the ''$db->connect()'' statement
  
-{{tag>[SQL_Server windows active]}} 
-====== mssql (Windows) ====== 
-<WRAP left 300px box> 
-|Driver Name|mssql| 
-|Status|Deprecated| 
-|Windows|Yes| 
-|Unix|No| 
-</WRAP> 
-This driver was the primary connection method to SQL Server databases up to PHP Version 5.2. The windows dll associated with this driver (php_mssql.dll) was removed from the standard PHP distribution in PHP Version 3. There is no community support for this driver.   
  
-{{tag>[SQL_Server windows deprecated]}} 
 ------------------------------ ------------------------------
-====== mssql (Unix) ====== +===== How to create a connection under Linux ===== 
-<WRAP right box round> +Establishing a connection to a SQL server database from a Linux client can be difficult, but by installing the freetds tools as well as the Microsoft ones provides a highly useful tool, //**tsql**// 
-See Also: [[database:pdo#pdo_mssql|PDO driver for FreeTDS]] + 
-</WRAP+In the example, our database is running on a server 192.168.0.65
-<WRAP left 300px box+<code> 
-**This is the preferred driver for connecting to a SQL server database from Linux/Unix clients.** +# tsql -LH 192.168.0.65 
-|Driver Name|mssql| +    ServerName STUDY 
-|Status|Active| +   InstanceName SQLEXPRESS 
-|Windows|No| +    IsClustered No 
-|Unix|Yes|+        Version 12.0.2000.8 
 +            tcp 55644 
 +             np \\STUDY\pipe\MSSQL$SQLEXPRESS\sql\query 
 +</code
 +The response from the command tells us the 
 +  The SQL server instance is visible from the client 
 +  * the service is running on port 55644 
 + 
 +We can now create a connection string: 
 + 
 +<code php> 
 +$db = ADONewConnection('mssqlnative'); 
 +$db->connect('192.168.0.65,55644',$user,$pass,'NORTHWND'); 
 +</code> 
 +-------------------------------------- 
 + 
 +===== mssql (Unix) ===== 
 +<WRAP right box round 300px> 
 +== Specification == 
 +^Driver Name|mssql| 
 +^Data Provider|mssql| 
 +^Status|Active((This driver is actively supported by ADOdb project members))
 +^Windows|No| 
 +^Unix|Yes| 
 +^ADOdb V5|Yes| 
 +^ADOdb V6|Yes| 
 +== Alternatives == 
 +[[v5:database:pdo#pdo_mssql|PDO driver for FreeTDS]]
 </WRAP> </WRAP>
 +**This is the preferred driver for connecting to a SQL server database from Linux/Unix clients, when the PHP version is less than 7.0**
 This driver provides access to Microsoft SQL Server databases from unix systems via Freetds This driver provides access to Microsoft SQL Server databases from unix systems via Freetds
  
-{{tag>[SQL_Server unix active freetds]}} +{{tag>[SQL_Server unix active freetds tier1]}} 
-====== mssqlpo ====== +-------------------------------------- 
-<WRAP left 300px box> +===== mssql (Windows) ===== 
-|Driver Name|mssqlpo| +<WRAP right box round 300px> 
-|Status|Active+== Specification == 
-|Windows|No| +^Driver Name|mssql| 
-|Unix|Yes|+^Data Provider|mssql| 
 +^Status|Obsolete((This driver will be removed in ADOdb version 6))| 
 +^Windows|Yes| 
 +^Unix|No| 
 +^ADOdb V5|Yes ((PHP Version 5.2 and lower))| 
 +^ADOdb V6|No| 
 +</WRAP
 + 
 +This driver was the primary connection method to SQL Server databases up to PHP Version 5.2. The windows dll associated with this driver (php_mssql.dll) was removed from the standard PHP distribution in PHP Version 5.3. There is no community support for this driver.   
 + 
 + 
 +---------------------------------------------------- 
 +===== mssqlpo ===== 
 +<WRAP right box round 300px
 +== Specification == 
 +^Driver Name|mssqlpo| 
 +^Data Provider|mssql| 
 +^Status|Inactive((This driver is not actively supported or enhanced by ADOdb project members, but you can provide fixes and enhancements if you have the expertise))
 +^Windows|No| 
 +^Unix|Yes| 
 +^ADOdb V5|Yes| 
 +^ADOdb V6|Yes|
 </WRAP> </WRAP>
 This driver provides undocumented portability extensions to the Unix mssql driver This driver provides undocumented portability extensions to the Unix mssql driver
Line 62: Line 162:
 {{tag>[SQL_Server unix windows active portable]}} {{tag>[SQL_Server unix windows active portable]}}
  
-====== mssql_n ====== +===== mssql_n ===== 
-<WRAP left 300px box> +<WRAP right box round 300px
-|Driver Name|mssqlpo| +== Specification == 
-|Status|Deprecated+^Driver Name|mssqlpo| 
-|Windows|No| +^Data Provider|mssql| 
-|Unix|Yes|+^Status|Inactive((This driver is not actively supported or enhanced by ADOdb project members, but you can provide fixes and enhancements if you have the expertise))
 +^Windows|No| 
 +^Unix|Yes| 
 +^ADOdb V5|Yes| 
 +^ADOdb V6|Yes|
 </WRAP> </WRAP>
-This driver appears to provide Unicode enhancements to the mssql driver+This driver appears to provide Unicode enhancements to the mssql driver. You can set character sets using the [[v5:reference:connection:setconnectionparameter|setConnectionParameter()]] command
  
-{{tag>[SQL_Server unix deprecated unicode supported]}}+{{tag>["Microsoft SQL Server" unicode freetds windows]}}
v5/database/microsoft_sql_server.txt · Last modified: 2022/11/15 02:13 by mnewnham