作業系統是win server 2008 r2,資料庫是sql server 2008,PHP Version 5.4.14,
在輸出的phpinfo當中看
-------------------------------------------------------------------------------------
PDO support enabled
PDO drivers mysql, sqlite, sqlsrv
但是想使用sqlsrv訪問資料庫就是不行,始終出現“HTTP 錯誤 500.0”提示,
-------------------------------------------------------------------------------------
模組 FastCgiModule
通知 ExecuteRequestHandler
處理常式 PHP54_via_FastCGI
錯誤碼 0x00000000
這是訪問的作業碼,其實是從microsoft driver for PHP for sql server上拷貝的常式:
"myDB1");/* Connect using Windows Authentication. */$conn = sqlsrv_connect( $serverName, $connectionInfo);if( $conn === false ){ echo "Unable to connect.
"; die( print_r( sqlsrv_errors(), true));}else echo "great!
";?>
回複討論(解決方案)
配置php.ini,??php?mssql的?展即可.
PDO drivers mysql, sqlite, sqlsrv ???
只有這個?
你單寫一個程式
看看輸出什麼
PDO drivers mysql, sqlite, sqlsrv ???
只有這個?
你單寫一個程式
看看輸出什麼
輸出的是HTTP 錯誤 500.0 - Internal Server Error呀!
難道裝的PHP沒裝對?因為是server2008系統,所以用的是微軟那個web platform installation安裝的PHP 5.4,確實沒找到system32下的fcgiXXX.dll,但是phpinfo()又能輸出資訊。。。。
PDO
---------------------------------------
PDO support enabled
PDO drivers mysql, sqlite, sqlsrv
確實只有這幾個呀!是不是還要安裝啥呢?
配置php.ini,??php?mssql的?展即可.
已經百度了好多下了,發現對5.2以下版本可以用,以上版本的因為sql server資料庫版本不同,所以這方法不推薦了。而且我也嘗試了下載php_mssql.dll,然後添加註釋,不起作用呀
我用的php版本是5.2.6 一直在正常使用中.
不要開玩笑!
單獨一句
var_dump(function_exists('sqlsrv_connect'));
這麼可能是 HTTP 錯誤 500.0 - Internal Server Error
至多是 bool(false)
不要開玩笑!
單獨一句
var_dump(function_exists('sqlsrv_connect'));
這麼可能是 HTTP 錯誤 500.0 - Internal Server Error
至多是 bool(false)
呵呵,剛才確實是那樣的哈!
現在裝成5.3啦,又下載了microsoft driver for PHP for sql server,終於不出錯http500啦!
就是5.3的ini檔案和5.4的差別很大,不但要填索引值,還要添加鍵名稱
不要開玩笑!
單獨一句
var_dump(function_exists('sqlsrv_connect'));
這麼可能是 HTTP 錯誤 500.0 - Internal Server Error
至多是 bool(false)
呵呵,剛才確實是那樣的哈!
現在裝成5.3啦,又下載了microsoft driver for PHP for sql server,終於不出錯http500啦!
就是5.3的ini檔案和5.4的差別很大,不但要填索引值,還要添加鍵名稱 那問題是否解決?
Unable to connect.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2]. [message] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )
------------------------------------------------------------------------------------------
唉,又浪費倆小時,還是不行呀!找到問題了,但是不知道怎麼解決的!
我用的微軟的web platform install安裝PHP,它會自動安裝一個SQL server 2012 native client的軟體。只要把它卸載了,PHP就再也無法運行了,即使裝了fastcgi也沒用。但是裝了它以後,我的sql server 2008資料庫就肯定是連不起來的。可以加分加到100粉的,請大俠再給看下吧!
Unable to connect.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2]. [message] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )
------------------------------------------------------------------------------------------
唉,又浪費倆小時,還是不行呀!找到問題了,但是不知道怎麼解決的!
我用的微軟的web platform install安裝PHP,它會自動安裝一個SQL server 2012 native client的軟體。只要把它卸載了,PHP就再也無法運行了,即使裝了fastcgi也沒用。但是裝了它以後,我的sql server 2008資料庫就肯定是連不起來的。可以加分加到100粉的,請大俠再給看下吧!
引用的DLL檔案版本不對
還是版本不相容的問題....
最後也沒解決呀,逼得只能現學asp.net了,要不是需求SQL server,我用mysql輕鬆就搞定了。
微軟太自私了,明顯是想讓P(拍)H(黃)P(片)的餓死呀!!!
我的可以,PHP Version 5.4.16 連結 sql2008 連結成功
用sqlsrv 3.0 ,2.0的沒有試過,方法是
php.ini 加入
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
資料庫連結:
$conn= new PDO("sqlsrv:server=127.0.0.1;database=abc","user","123456") or die ("PDO Connection faild.");