deepin下要如何安装php7 并连接到sqlser
Tofloor
poster avatar
lo******11@sina.com
deepin
2017-06-07 18:59
Author
本帖最后由 loc711 于 2017-6-7 11:01 编辑

按微软的教程安装了php7下的sqlsrv和pdo_sqlsrv,但是测试时出现错误,PHP Fatal error:  Uncaught Error: Call to undefined function sqlsrv_connect() ,unixodbc,mssql-tools都安装了,查看phpinfo,相关组件都已安装好了,有没有成功的在deepin下使用php7 连接sqlser的朋友?请给予指导,谢谢。
Reply Favorite View the author
All Replies
avatar
jingle
deepin
2017-06-07 19:18
#1
你具体如何操作的 ?

现在仓库有
mssql-server - Microsoft(R) SQL Server(R) Relational Database Engine
mssql-tools - Tools for Microsoft(R) SQL Server(R)

Reply View the author
avatar
151******55
deepin
2017-06-07 19:41
#2
报错提示的意思是未定义的sqlsrv_connect函数,一般出现此问题原因在于:php没加载到sqlsrv的扩展。先确认是否安装了PHP的sqlsrv扩展
Reply View the author
avatar
151******55
deepin
2017-06-07 19:46
#3
查了手册,貌似这个扩展不支持Linux,没用过。

The SQLSRV extension can be used on the following operating systems:

Windows Vista Service Pack 2 or later
Windows Server 2008 Service Pack 2 or later
Windows Server 2008 R2
Windows 7

http://php.net/manual/en/sqlsrv.requirements.php
Reply View the author
avatar
lo******11@sina.com
deepin
2017-06-07 21:01
#4
本帖最后由 loc711 于 2017-6-7 13:03 编辑

在deepin 下安装的php7.0, 扩展已经安装了,信息如下:

pdo_sqlsrv
pdo_sqlsrv support        enabled
ExtensionVer        4.0.8.0
Directive        Local Value        Master Value
pdo_sqlsrv.client_buffer_max_kb_size        10240        10240
pdo_sqlsrv.log_severity        0


sqlsrv
sqlsrv support        enabled
ExtensionVer        4.0.8.0
Directive        Local Value        Master Value
sqlsrv.ClientBufferMaxKBSize        10240        10240
sqlsrv.LogSeverity        0        0
sqlsrv.LogSubsystems        0        0
sqlsrv.WarningsReturnAsErrors        On        On

扩展安装没问题,按微软的linux-4.0_install_instructions.pdf中的内容操作的,执行pdf中给的测试代码,不成功。测试代码:
/**
* Created by PhpStorm.
* User: sto
* Date: 17-6-7
* Time: 上午9:51
*/

$serverName = "192.168.0.2\\sql,1433";
$connectionOptions = array(
"Database" => "demo",
"Uid" => "sa",
"WD" => "123456"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
//Select Query
$tsql= "SELECT @@Version as SQL_VERSION";
//Executes the query
$getResults= sqlsrv_query($conn, $tsql);
//Error handling
if ($getResults == FALSE)
die(FormatErrors(sqlsrv_errors()));
?>
<h1> Results : h1>
while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
echo ($row['SQL_VERSION']);
echo ("
"
);
}
sqlsrv_free_stmt($getResults);
function FormatErrors( $errors )
{
/* Display errors. */
echo "Error information:
"
;
foreach ( $errors as $error )
{
echo "SQLSTATE: ".$error['SQLSTATE']."
"
;
echo "Code: ".$error['code']."
"
;
echo "Message: ".$error['message']."
"
;
}
}
?>
Reply View the author
avatar
186******39
deepin
2017-09-25 16:36
#5
本帖最后由 l0rraine 于 2017-9-25 08:38 编辑

我用freetds安装成功了的,你可以试试啊
我的大体安装过程,可以参考下
apt intall libsybdb5 freetds-common php7.1-sybase

apt install php7.1-dev

./configure --prefix=/usr/local/freetds --enable-msdblib

php-7.1.1/ext/pdo_dblib
./configure --with-php-config=/usr/bin/php-config --with-pdo-dblib=/usr/local/freetds

测试是否能成功连接数据库
/usr/local/freetds/bin/tsql -H 数据库服务器IP  -H 10.69.76.10 -p 1433 -U sa



Reply View the author