Denis V Denis V - 4 months ago 26
PHP Question

PHP SQL Server : 500 Internal server error with specific query

I'm working with PHP Version 5.4.45, my website and a SQL Server database hosted on Microsoft Azure.

At this moment I just have 2 tables:

  • users (ID [int PK], fname [vchar], lname [vchar]);

  • user_login (ID [int PK], userID [int], login [datetime]);

I had inserted data on SSMS just for tests.

On my website I run a query to give me a list of registered users and it returns all relevant information (2 rows).

When I run a query to return a list of users login that throws a 500 Internal server error.

  1. When my 1st "echo" is the ID or userID, it returns ONE value and nothing more.

  2. When my 1st "echo" is the login (datetime), it doesn't shows anything, and the next "echo" in code too.

With this I conclude that the error's on login column.

I've read that 'bog queries' could do this error (I only have 30 rows for each userID, 60 for my 2 users) but, for test, I limited my query to only 5 records.

The query that I'm trying at this moment works on SSMS.

I can't access to the PHP error log file.


$userID = 1;
$uid = "xxx";
$pwd = "xxx";
$serverName = "xxx";
$connectionInfo = array( "Database"=>"Development", "UID"=>$uid, "PWD"=>$pwd);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )
// echo "Connection established.\n";
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));

$sql = "SELECT * FROM dbo.userLogin WHERE userID=1 AND ID BETWEEN 5 AND 10 ORDER BY ID ASC ";
$stmt = sqlsrv_query( $conn, $sql);

if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));

while($sql = sqlsrv_fetch_array($stmt)) {
$id = $sql["ID"];
$login = $sql["login"];
$num_row = count($login);

for ($i = 0; $i < $num_row; $i++) {
echo "

Query working in SSMS

enter image description here



Try this $sql = "SELECT ID, userID, CONVERT(nvarchar(50),[Login],120) as [Login] FROM dbo.userLogin WHERE userID=1 AND ID BETWEEN 5 AND 10 ORDER BY ID ASC ";