#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    MSSQL Query Issue


    I am building a new intranet web server for my organization. It is based on Ubuntu Server 12.04 and is using PHP5.3.10, Apache2, and FreeTDS for MSSQL access. My FreeTDS configuration seems to be correct. I am able to connect to my database servers.

    However, if I issue a SQL statement like [SELECT * FROM SOME table WHERE recordid = 1] I get a browser reset message. If I modify the SQL statement to [SELECT fieldname1,fieldname2 FROM SOME table WHERE recordid = 1] I get good results.

    I suspect this is a PHP issue, but honestly unsure.

    Anybody seen this one before?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,130
    Rep Power
    9398
    The "browser reset" is probably because something mucked up in Apache or PHP. Can you check their logs for relevant messages?

    And an obvious question: are you sure the query is correct, both logically and for the code trying to use it?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    The "browser reset" is probably because something mucked up in Apache or PHP. Can you check their logs for relevant messages?

    And an obvious question: are you sure the query is correct, both logically and for the code trying to use it?
    I did not see any clues in the Apache log (/var/log/apache2/error.log). Its appears to be starting fine and there are no PHP error messages as well. My full code is:
    PHP Code:
    $conn mssql_connect("MSSQLSRV","user","pw");
        
    mssql_select_db('dbname'$conn);
        
    $flds = ($_GET['opt'] == 0)? "*" "lastname, firstname";
        
    $sql "SELECT ".$flds." FROM employees where employee_id = 'X01'";
            
        
    $result mssql_query($sql);
        
    $row mssql_fetch_assoc($result);
        
        if(!
    $conn){echo "Connection Failed!<br><br>";}
        if(!
    $result){echo "Result Failed!<br><br>";}
        
        echo 
    "<pre>";
        
    print_r($row);
        echo 
    "</pre>"
    If I pass in '?opt=0' through the url I get "The connection to the server was reset while the page was loading" message. This is the option that uses the '*' in the SQL query statement.

    If I change it to '?opt=1' I get the returned row as an array:
    PHP Code:
    Array
    (
        [
    lastname] => Doe
        
    [firstname] => John

    I don't have this issue on the webserver I am replacing. It is a Fedora 7, Apache 2.2.14, PHP 5.3.1 system.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Solved it!


    It was a php.ini setting. Changed mssql.datetimeconvert = On to Off.

    Geesh!!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    1
    Rep Power
    0

    FYI - Developer Best Practice


    Originally Posted by Slingb0y
    It was a php.ini setting. Changed mssql.datetimeconvert = On to Off.

    Geesh!!
    While you solved the problem it is important to note that it is a bad developer habit to form any query with Select * from table at any time.

    That forces a table scan that can impede performance. It is always in your best interest to state the columns specifically as in Select id, name, description, date (etc) from Table

    Comments on this post

    • Jacques1 agrees

IMN logo majestic logo threadwatch logo seochat tools logo