如何使用PHP7使mssql_connect正常工作? [英] How do I get mssql_connect to work using PHP7?
问题描述
使用PHP7将Web应用程序移植到服务器时,遇到一个问题:我无法使mssql_connect正常工作.我发现mssql在PHP7上尚无法运行(或永远无法运行).
While porting a web app to a server using PHP7, I encounter one problem: I can't get mssql_connect to work. I found out that mssql doesn't work yet (or will never work) on PHP7.
在Ubuntu(Nginx,php-fpm)上使用PHP7连接到MSSQL的最快方法是什么?
What's the quickest way to connect to MSSQL using PHP7 on Ubuntu (Nginx, php-fpm)?
推荐答案
连接功能不再是mssql_connect().自php 5.3起已弃用.现在在php 7上,这个旧功能消失了.但是,请放心;)现在,您可以改用sqlsrv_connect()函数.
The connection function is not mssql_connect() anymore. Since php 5.3 it's been deprecated. Now on php 7 this old function vanishes. But don't worry ;) Nowadays you can use the sqlsrv_connect() function instead.
请记住,在新方法中,您需要正确设置参数.有一些区别.这里有一个小例子.
Keep in mind that in the new method you need to set up the parameters properly. There are some differences. Here comes a little example.
<?php
$serverName = "serverName\sqlexpress, 1542"; //serverName\instanceName, portNumber (1433 by default)
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Successfuly connected.<br />";
}else{
echo "Connection error.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
也许这个答案对您来说有点晚了,但我希望对某人来说还不算太晚.
May be this answer comes a bit late for you but I hope it is not too late for someone.
这篇关于如何使用PHP7使mssql_connect正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!