Jump to content

Assigning the result of sqlsrv_query to a class variable


PHPUser322

Recommended Posts

Hello,

 

I am creating a class which contains one private function that deals with connecting to a SQL Server and executing the sql that is passed in to that function.

I have defined a class variable which is assigned the value of sqlsrv_query like so.

 

$this->QueryResult = sqlsrv_query($conn,$sql);

I have placed private $QueryResult at the top of my class.

 

The other public methods call this private function to assign the result set to the class variable, the private method returns and then the public methods loop through the results array like so.

 

while($row = sqlsrv_fetch_array($this->QueryResult))

 

.. but the while loop never gets entered.

 

If I declare everything in the same method then it works, however there are going to be several public methods that will use this private method and I don't want to duplicate all the database coding.

 

Hope someone can help

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.