PHP连接SqlServer心得(史上最全)
分类:PHP时间: 2016年5月20日
首先,说一下为什么要写 《PHP连接SqlServer心得(史上最全)》这篇文章?一、这种问题PHP程序员一般很少用到,基本是PHP+MySQL,二、遇到问题网上很多都是重复的内容,并且不能完全解决问题。总的来说,就是PHP连接SqlServer可能遇到的问题和PHP程序员雷雪松的解决思路都总结出来分享给大家,大家想使用PHP连接SqlServer的时候直接使用就可以了。
PHP程序员雷雪松使用PHP连接SqlServer的环境:windows2008 64位系统,PHP集成环境wamp(软件版本包含apache2.4.9,mysql5.6.17,php5.5.12)。顺便说一下在PHP程序员雷雪松的个人博客中还有两篇关于PHP和SqlServer的文章,有兴趣的可以看一下 Linux下PHP扩展MSSql的安装和 Thinkphp操作MsSQL心得。
在PHP5.3以前还可以使用mssql系列函数,PHP官网mssql简介提示在PHP 5.3或更高版本Windows这个扩展是不可用的,在PHP7.0.0以后mssql这个功能就被删除了,使用PDO_SQLSRV (Windows only)、PDO_ODBC、SQLSRV (Windows only)、Unified ODBC API扩展替代。所以在windows系统中,PHP连接SqlServer只有PDO_SQLSRV (Windows only)、SQLSRV (Windows only)两种方式。
1、引入PHP扩展的时候一定要注意PHP的版本,ts还是nts,请参考PHP程序员雷雪松的博客 《PHP版本的区别与用法详解》。
2、如果使用Microsoft PHP 驱动程序的版本是3.1或者3.2时,需要先在微软官网可以下载安装Microsoft ODBC Driver 11 for SQL Server。
3、微软提供的PHP扩展sqlsrv和pdo_sqlsrv的PHP只支持32位,也就是x86平台,不支持64位,如果需要安装64的PHP扩展你就必须用非官方的sqlsvr和pdo_sqlsrv扩展,32位的可以直接去微软官网下载。 PHP扩展sqlsrv和pdo_sqlsrv下载非官方32位和64位地址,32位支持5.3、5.4、5.5、5.6,64位支持5.5、5.6。
4、安装完sqlsvr扩展以后,打开phpinfo()查看是否有sqlsvr和pdo_sqlsrv,注意如果使用命令行运行时,一定要主要配置文件。命令:php.exe -c php.ini -f file.php。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
