sqlsrv_connect没有像mysql_connect.it那样返回对象,只是返回ResourceId

时间:2014-08-02 06:44:26

标签: php mysql sqlsrv

I am trying to get data from sqlserver using PHP.
I have connected to the server by using sqlsrv DLLs.
i can able to get the data from server using sqlsrv_query() function.
but i am using the class for executing the queries,
i mean i am not calling queries directly,
instead i using  the following class as follows ,  
   class mssql{
         //function to connect with mssql server
            public function connect(){  
                $serverName = $this->dbhost; //serverName\instanceName
                $connectionInfo = array( "Database"=> $this->dbname, "UID"=> $this->dbuser, "PWD"=> $this->dbpass);
                $this->connection = sqlsrv_connect($serverName, $connectionInfo);
                return $this->connection;  // here it is returning ResourceId insted object
             }
        //function to excute select qyeury       
            public function query($query, $remember_result=TRUE){
                $result = sqlsrv_query($query, $this->connection);
                return $result;     
             }
    }

//我正在为该类创建对象     $ db1 = new mssql($ C-> DB_HOST,$ C-> DB_USER,$ C-> DB_PASS,$ C-> DB_NAME);
    现在我正在使用对象执行如下所示的选择查询,     $ r = $ this-> db1-> query(' SELECT * from tblveterinary',FALSE);           问题是它返回null,           这背后的问题是sqlsrv_connect返回资源ID,           但要执行所有功能,我需要sqlsrv_connect返回对象。             请建议我这个,           谢谢。

0 个答案:

没有答案