Your pretty far off with your code, and I'm not sure which version of PHP your using. Plus your code is very primitive and not object oriented like for PHP versions 7 and up. You have to create a db connector as a class and call that db connector. Then create a query. Next run that query with the db connector which creates a result. The result can be false if nothing comes back, or can be a array of records in which you fetch them. Finally you call that array that was returned and convert them to rows. I packed the rows into an object that I created, and return the object instead of an array. The code your writing is very the year 2000, and is quite old and outdated. Nobody in western democracies are writing code like that anymore. PHP 7.4 example, what you should be learning. Hope that helps you, and PHP Storm by Jet Brains is the preferred editor or IDE for PHP.
public static function getUsers(): Users {
$users = new Users();
$query = "
SELECT
uid,
Username
FROM \[user\]
WHERE User\_type <> 'xxxxxxx'
ORDER BY Username";
$conn = DbConnectRepository::createConn();
$result = sqlsrv\_query($conn, $query) or die(" getUsers " . \_\_LINE\_\_ . " - " . $query . ' - ' . print\_r(sqlsrv\_errors()));
while ($row = sqlsrv\_fetch\_array($result)) {
$user = new User();
$user->setUserId($row\[0\]);
$user->setUserName($row\[1\]);
$users->add($user);
}
return $users;
}
If it ain't broke don't fix it Discover my world at jkirkerx.com