1

I created a script to perform a few select queries on a mssql database, but the script seems to stop dead on certain queries, without returning any errors. The browser receives a completely empty response from the server. On Firefox, it prompts to download a blank .php file; on Chrome it returns "Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error."; and on IE8 it returns "Page cannot be displayed".

The query is

$sql = "SELECT *
    FROM EmployeeHours
    WHERE (EmployeeId = '".$staff_id."')
    AND (TimeIn > DATEADD(second, ".$week_start.", CONVERT(DATETIME, '1970-01-01', 102)))
    AND (TimeOut < DATEADD(second, ".$week_end.", CONVERT(DATETIME, '1970-01-01', 102))
        OR TimeOut IS NULL)
    ORDER BY UTCDateAdded DESC";
$query = mssql_query($sql);

$staff_id is a simple int. $week_start and $week_end are unix timestamps.

I don't think it's the query itself, because it runs fine in MSSQL Server Management Studio and returns the correct data. I can also simplify the query down to "SELECT TOP 1 * FROM EmployeeHours" with no WHERE conditions and it still fails.

Setting error_reporting to E_ALL has no effect. It doesn't execute anything past the mssql_query(). Anything printed or echoed before the query doesn't appear in the resulting file either.

I can verify that it is connected to the the correct database, because I can run some other queries on tables in the same database and get results through the script.

5
  • 2
    Every time you create sql with unescaped $variables, God kills a kitten. Commented Mar 15, 2011 at 18:07
  • @cHao They are escaped before the bit of the script that I posted. Commented Mar 15, 2011 at 18:11
  • It's not a good idea to use the MSSQL extension, it's not available since PHP 5.3, you can use the official Microsoft driver SQLSRV (here you have the API doc) which is much more feature-rich but have some weird problems, like most of the Microsoft API's. Commented Mar 15, 2011 at 18:36
  • What web server? (IIS? Apache?) What does the web server's error log say? I've seen a problem like this before when a script I wrote was actually causing Apache to segfault - thus the response was never fully sent. Commented Mar 15, 2011 at 21:19
  • @NuclearDog Apache. Error log doesn't show me anything from that script. Commented Mar 16, 2011 at 13:07

3 Answers 3

1

Tried switching to the ODBC extension instead of MSSQL ext and it would hang when using select queries with odbc_exec(). Found no fix for that either.

Finally got it to work by switching to PDO.

Sign up to request clarification or add additional context in comments.

Comments

0

The problem is date type in result, use cast for date data types. Example: SELECT my_day, other_field FROM my_table use SELECT convert(varchar(19), my_day, 120) as my_day, other_field FROM my_table

use format your preference

Comments

0

In my case I was retrieving a float, a varchar(2) , two longs, and a "money" using PDO (dblib). The money value that was causing this was negative - a credit. I ended up changing the money field to a float, and the query would execute without the ERR_EMPTY_RESPONSE. Hopefully this will shorten someone else's time spent on this issue!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.