Table of Contents
php5.3不能连接mssql数据库的解决方法,php5.3mssql
Home php教程 php手册 php5.3不能连接mssql数据库的解决方法,php5.3mssql

php5.3不能连接mssql数据库的解决方法,php5.3mssql

Jun 13, 2016 am 09:17 AM
mssql mysql database php database Solution

php5.3不能连接mssql数据库的解决方法,php5.3mssql

本文实例讲述了php5.3不能连接mssql数据库的解决方法。分享给大家供大家参考。具体分析如下:

自从php5.3之后系统就不支持mssql_connect这个函数连接了,以前我也讲可以使用com接口来实现,现在我再介绍解决php5.3不能连接mssql数据库另一方法.

windows系统下,PHP5.3以上的版本已经不支持mssql扩展.

首先http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx 点击 get it 下载SQLSRV20.EXE。

将文件解压到php的扩展文件夹ext下,打开php.ini在结尾添加:

复制代码 代码如下:

[PHP_PDO_SQLSRV]
extension=php_pdo_sqlsrv_53_nts_vc6.dll
[PHP_SQLSRV]
extension=php_sqlsrv_53_nts_vc6.dll


保存后重启apache即可,附上简单的php连接的例子,代码如下:

复制代码 代码如下:

$serverName = "(127.0.0.1)";
$connectionInfo = array( "UID"=>"root",
"PWD"=>"root2010",
"Database"=>"master");
 
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.n";
}
else
{
echo "Connection could not be established.n";
die( print_r( sqlsrv_errors(), true));
}
?>


我使用的是wamp5.1集成安装包,在windows server 2008上面做的测试,php5.4以上版本测试没有成功.

如果使用这个扩展连接Sql server 2005以上版本的sql server(如sql server 2008),你还需要在机器上先安装 SQL Server Native Client :http://download.microsoft.com/download/0/E/6/0E67502A-22B4-4C47-92D3-0D223F117190/sqlncli.msi

这个扩展为php新增了一系列sqlsrv_开头的函数,函数参考如下:

复制代码 代码如下:

sqlsrv_begin_transaction
sqlsrv_cancel
sqlsrv_client_info
sqlsrv_close
sqlsrv_commit
sqlsrv_configure
sqlsrv_connect
sqlsrv_errors
sqlsrv_execute
sqlsrv_fetch
sqlsrv_fetch_array
sqlsrv_fetch_object
sqlsrv_fetch_metadata
sqlsrv_free_stmt
sqlsrv_get_config
sqlsrv_get_field
sqlsrv_has_rows
sqlsrv_next_result
sqlsrv_num_fields
sqlsrv_num_rows
sqlsrv_prepare
sqlsrv_query
sqlsrv_rollback
sqlsrv_rows_affected
sqlsrv_send_stream_data
sqlsrv_server_info

更多详细的说明可以在刚才的自解压的文件中有个 SQLServerDriverForPHP.chm 帮助文件中可以找到打开后点击API Reference节点.

另外看一种odb连接方式,代码如下:

复制代码 代码如下:

$dbhost = '';
$dbuser = ''; //你的mssql用户名
$dbpass = ''; //你的mssql密码
$dbname = ''; //你的mssql库名
$connect=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser","$dbpass");
$sql="select * from content";
$exec=odbc_exec($connect,$sql);
while($row = (odbc_fetch_array($exec)))
{
$row['id']   //?取字段值

}

希望本文所述对大家的php程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

See all articles