![](/img/trans.png)
[英]Ubuntu 14.04, Apache 2.4.7, Phpbrew and PHP7 renders PHP files only as plain text
[英]Apache 2.4.7 on Ubuntu 14.04 will not connect to MSSQL through PHP 5.5
我正在嘗試使用標題中列出的平台連接到遠程MSSQL服務器。 我安裝了FreeTDS和所有相關的ODBC包。 這是我的freetds.conf:
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[DEVSQL]
host = x.x.x.x
instance = DEVSQL
tds version = 8.0
這是我的odbc.ini:
[ODBC Data Sources]
DEVSQL = FreeTDS Connection Server
[DEVSQL]
Description = MSSQL Server
Driver = freetds
ServerName = DEVSQL
Database = test
TDS_Version = 8.0
這是我的PHP代碼:
<?php
$dbname = "test";
$servername = "DEVSQL";
$username = "myuser";
$password = "mypassword";
try{
$db = new PDO('odbc:Driver=FreeTDS; Server='.$servername.'; Database='.$dbname.'; UID='.$username.'; PWD='.$password.';');
Database='.$dbname.'; UID='.$username.'; PWD='.$password.';');
}
catch(PDOException $exception){
die("Unable to open database.<br />Error message:<br /><br />$exception.");
}
echo '<h1>Successfully connected!</h1>';
?>
我可以使用終端中的以下命令連接正常:
TDSVER=8.0 tsql -S devsql -U myuser -P mypassword
以及:
isql -v devsql myuser mypassword
但是當我在FireFox中瀏覽到index.php時,我收到以下錯誤:
異常'PDOException',消息'SQLSTATE [08001] SQLDriverConnect:0 [unixODBC] [FreeTDS] [SQL Server]無法連接到數據源'/var/www/html/index.php:16堆棧跟蹤:#0 / var / www / html / index.php(16):PDO - > __ construct('odbc:Driver = Fre ...')#1 {main}。
任何幫助非常感謝! Alos,如果有人有更好的方法從使用php的linux機箱連接到sql server,我全都耳朵。 再次感謝!
編輯:我忘了提到:Ubuntu和Apache正在Win7主機上的VM實例中運行。 同一台計算機上的Win7環境是SQL Server運行的位置。 我不確定這是否相關,因為他們溝通得很好,但我想我會把它扔出去。
這篇文章對我有幫助,在我的例子中是Yii與MySql同步到MSSQL。 希望對你有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.