PHPUser322 Posted May 21, 2011 Share Posted May 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237037-assigning-the-result-of-sqlsrv_query-to-a-class-variable/ Share on other sites More sharing options...
trq Posted May 22, 2011 Share Posted May 22, 2011 We need to see your code. Quote Link to comment https://forums.phpfreaks.com/topic/237037-assigning-the-result-of-sqlsrv_query-to-a-class-variable/#findComment-1218602 Share on other sites More sharing options...
xyph Posted May 22, 2011 Share Posted May 22, 2011 I think you want to create a method like this public function setQueryResult ( $value ) { $this->QueryResult = $value; } then use $obj->setQueryResult( sqlsrv_query($conn,$sql) ); Quote Link to comment https://forums.phpfreaks.com/topic/237037-assigning-the-result-of-sqlsrv_query-to-a-class-variable/#findComment-1218612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.