2016-07-18 115 views
-1

我將開發一個簡單的應用程序。我的應用程序將通過PHP Web服務與現場數據庫進行通信。在本地測試我的應用程序時,一切正常。但不是當我搬到住服務器(我的數據庫和Web服務的文件服務器是在Live服務器((IE)GoDaddy的)。如何將Live SQL數據庫連接到Android應用程序

<?php 
require "db_config.php"; 

$user_name=$_POST['login_name']; 
$user_pass=$_POST['login_pass']; 
$sql_query = sqlsrv_query($conn, "select * from user_auth where user_name='".$user_name."' and user_pass ='".$user_pass."'" , array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET)); 

if(sqlsrv_num_rows($sql_query)>0) 
{ 
    echo "Login Success..Welcome"; 
} 
else 
{ 
    echo "Login Failed.......Try Again.."; 
} 
?> 

這是測試登錄活動的代碼。我跑這之後我收到此錯誤:

Array ([0] => Array ([0] => 28000 [SQLSTATE] => 28000 [1] => 18452 [code] => 18452 [2] => 
[Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed. 
The login is from an untrusted domain and cannot be used with Windows authentication. 
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed. 
The login is from an untrusted domain and cannot be used with Windows authentication.) 
[1] => Array ([0] => 28000 [SQLSTATE] => 28000 [1] => 18452 [code] => 18452 
[2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed. 
The login is from an untrusted domain and cannot be used with Windows authentication. 
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.)) 

我除外,而在本地得到這個問題來改變我的本地SQL管理Studio軟件的一些配置,也是我可以使用一些DLL文件像(請在php.ini一個變化文件)

extension=php_pdo_sqlsrv_55_ts.dll 
extension=php_sqlsrv_55_ts.dll 

這是本地機器,但是當我使用實時數據庫時,如何配置我的在線數據庫?如果有任何可能的方式像本地機器一樣使用DLL文件?如果不是如何配置?

db_config.php

<?php 
$serverName = "servername"; 
$connectionInfo = array("Database"=>"testdb_mms"); 
$conn = sqlsrv_connect($serverName, $connectionInfo); 
if($conn === false) { 
    die(print_r(sqlsrv_errors(), true)); 
} 
?> 
+0

像錯誤說,你不能使用AD身份驗證。你的連接是在你已經連接的代碼之外完成的,也許在db_config.php –

+0

謝謝你的回覆@JamesZ,我附加了我的db_config文件,在帖子裏我只是想念那個。那麼使用哪種認證? – AndroidBoy

+0

使用SQL Server身份驗證,您需要爲此創建一個單獨的用戶/登錄名。 –

回答

0

修復它傳遞兩個參數(如用戶信息)

<?php 
//check all parameters 
$serverName = "server_name"; 
$uid = "testuser"; 
$pwd = "V*****"; 
$databaseName = "testdb_mms"; 

//check config 
$connectionInfo = array("UID"=>$uid,        
         "PWD"=>$pwd,        
         "Database"=>$databaseName); 

$conn = sqlsrv_connect($serverName, $connectionInfo); 
if($conn === false) { 
    die(print_r(sqlsrv_errors(), true)); 
} 
?> 
相關問題