sqlsrv_query(php)中的资源ID#3

时间:2015-12-04 10:01:42

标签: php

我收到一个小错误,我尝试了最好但没有结果。

有我的代码

$serverName = "localhost"; //serverName\instanceName
$connectionInfo = array( "Database"=>"Db_test", "UID"=>"sa", "PWD"=>"123456");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$stmt="SELECT CONVERT(VARCHAR(30),Money) as Money FROM userss WHERE NickName = 'dragon'";

$coin = sqlsrv_query($conn,$stmt);
echo $coin;

当我在SQL服务器中查询时,它返回1000 =>真

但是当我执行这个php文件时,它总是返回资源ID#3。

请帮助我,谢谢

1 个答案:

答案 0 :(得分:0)

在我的所有api中遇到同样的问题.. 在echo sqlsrv_query();给出了resopnse资源ID#3。

以下是我的代码。

 <?php
    // the connection part of the code.......
    $connectionInfo = array( 
    "UID"=>$uid,"PWD"=>$pwd,"Database"=>$databaseName,"CharacterSet" => "UTF-8");   

    /* Connect using SQL Server Authentication. */    
  $conn = sqlsrv_connect( $serverName, $connectionInfo); 
  if( $conn === false ) {
       die( print_r( sqlsrv_errors(), true));
  }

   $username= $_REQUEST['username'];
   $password= $_REQUEST['password'];

  if($username && $password)
  {
    $query = "SELECT NAME,LOGINID,PASSWORD FROM SMS_ACCESS WHERE LOGINID = '$username' AND   PASSWORD = '$password'";
    /* Execute the query. */    
    $stmt = sqlsrv_query( $conn,$query);    
    $json = array(); 

    echo $stmt;

    if ( $stmt === false)    
    {       
        $json["status_code"] = "203";
        $json["status"] = "Error in execution";
        //echo "Error in statement execution.\n";    
        die( print_r( sqlsrv_errors(), true));    
        echo json_encode(['data'=>[$json]]);
    }     
    else     
    {    
            while($row = sqlsrv_fetch_array( $stmt,  SQLSRV_FETCH_ASSOC)) 
            {
                $json["name"] = $row['0'];
            }
        //echo json_encode(['status_code' => "200",'status' => "success",'data'=>[$json],'Msg' => "Login Successful !!"]);
    }    
  }
  else {
        $json["status_code"] = "203";
        $json["status"] = "Parameter Missing !!";   
        die( print_r( sqlsrv_errors(), true));  
        echo json_encode(['data'=>[$json]]);
  }

    /* Free statement and connection resources. */    
    sqlsrv_free_stmt($stmt);    
    sqlsrv_close( $conn);    
  ?>