1 year ago
#340180
Faye D.
Get single row from MSSQL query without while loop
For some further operations, I need to quickly get the MAX(UserId) of a table containing users. Is it safe to do the following?
$max_user = sqlsrv_fetch_array(sqlsrv_query($connection, "SELECT MAX(UserID) FROM z_users;"))[0];
I mean without using a loop like while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
Also, I noticed that using the code I wrote above returns an array with two elements: one with index 0 and another without an index but with the same value.
Like Array ( [0] => 1211 [] => 1211 )
Why is this happening?
php
sql-server
sqlsrv
0 Answers
Your Answer