2016-07-18 117 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)); 
} 
?> 
相关问题