Home Backend Development PHP Tutorial php5.3不能连接mssql数据库的解决方法_php技巧

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

May 16, 2016 pm 08:27 PM
mssql database Solution

本文实例讲述了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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to solve the problem of busy servers for deepseek How to solve the problem of busy servers for deepseek Mar 12, 2025 pm 01:39 PM

DeepSeek: How to deal with the popular AI that is congested with servers? As a hot AI in 2025, DeepSeek is free and open source and has a performance comparable to the official version of OpenAIo1, which shows its popularity. However, high concurrency also brings the problem of server busyness. This article will analyze the reasons and provide coping strategies. DeepSeek web version entrance: https://www.deepseek.com/DeepSeek server busy reason: High concurrent access: DeepSeek's free and powerful features attract a large number of users to use at the same time, resulting in excessive server load. Cyber ​​Attack: It is reported that DeepSeek has an impact on the US financial industry.

How to adjust Sesame Open Exchange into Chinese How to adjust Sesame Open Exchange into Chinese Mar 04, 2025 pm 11:51 PM

How to adjust Sesame Open Exchange to Chinese? This tutorial covers detailed steps on computers and Android mobile phones, from preliminary preparation to operational processes, and then to solving common problems, helping you easily switch the Sesame Open Exchange interface to Chinese and quickly get started with the trading platform.

Sesame Open Door Exchange App Official Download Sesame Open Door Exchange Official Download Sesame Open Door Exchange App Official Download Sesame Open Door Exchange Official Download Mar 04, 2025 pm 11:54 PM

The official download steps of the Sesame Open Exchange app cover the Android and iOS system download process, as well as common problems solutions, helping you download safely and quickly and enable convenient transactions of cryptocurrencies.

Sesame Open Door Exchange Web Page Login Latest version gateio official website entrance Sesame Open Door Exchange Web Page Login Latest version gateio official website entrance Mar 04, 2025 pm 11:48 PM

A detailed introduction to the login operation of the Sesame Open Exchange web version, including login steps and password recovery process. It also provides solutions to common problems such as login failure, unable to open the page, and unable to receive verification codes to help you log in to the platform smoothly.

How does sharding technology solve the problem of Ethereum expansion? How does sharding technology solve the problem of Ethereum expansion? Feb 27, 2025 pm 05:00 PM

Solutions: 1. Process transactions in parallel; 2. Reduce the burden on nodes; 3. Improve consensus efficiency, etc.

What should I do if I can't pay if I buy coins? Why is buying coins frozen? What should I do if I can't pay if I buy coins? Why is buying coins frozen? Mar 05, 2025 pm 06:45 PM

When trading on a digital currency trading platform, the most worrying situation is that the seller does not release the coins after buying them or the buyer cannot pay. Both of these situations will seriously affect subsequent transactions. This article will focus on how buyers can’t pay. What should I do if I can’t pay if I buy coins? When encountering situations where payment is not possible, you should first check your own payment method and account status, and then confirm whether the network and trading platform are operating normally. If the problem remains the same, contacting platform customer service is usually the most effective solution. Here are some more detailed solutions: Payment method issues: Some banks or credit card institutions may restrict cryptocurrency-related transactions, especially international payments. It is recommended to try to contact the bank or credit card company for the restrictions and seek temporary lifting; or use another payment method instead.

Binance cancellation of account teaching: What should I do if I didn't enter the recommendation code? Delete the account and register again! Binance cancellation of account teaching: What should I do if I didn't enter the recommendation code? Delete the account and register again! Mar 04, 2025 am 07:06 AM

Completely understand the process and precautions for deleting Binance account! This article will guide you in detail on how to delete a Binance account and provide key things to check before deleting it. Reasons for deleting Binance Account Analysis Users may choose to delete Binance Account for the following reasons: No recommendation code is filled in: Many users did not fill in the recommendation code when registering and missed the handling fee discount. Since Binance does not support post-fill filling, deleting an account and re-registering is the only solution. Change the exchange: The user may choose to change the exchange due to interface, functions or verification procedures, and decide to delete the Binance account. Security concerns: Exchange security incidents may cause users to worry and choose to delete accounts to reduce risks. Please be sure to confirm the process of deleting Binance account before deleting the account

Is Ethereum public chain congestion true? What is the solution? Is Ethereum public chain congestion true? What is the solution? Mar 03, 2025 pm 10:18 PM

Ethereum, as the leading smart contract platform, has flourished its decentralized applications (DApps) and decentralized finance (DeFi) ecosystems, making it one of the largest blockchains with user scale. However, with the continued growth of user numbers and application size, and the continuous increase in transaction fees, the user experience has been significantly affected. Is the Ethereum network congestion problem true? The answer is yes. This article will discuss this in-depth. Ethereum network congestion: The real problem Ethereum network congestion is an objective reality. As a distributed computing platform based on blockchain technology, it supports smart contracts, tokens and various decentralized applications. However, its inherent network architecture also presents challenges, with the most notable of which is network congestion. Embrace

See all articles