php5.3不能连接mssql数据库的解决方法,php5.3mssql
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程序设计有所帮助。

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



PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.
