mssql Bug?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    mssql Bug?

    hi all,

    i just encountered a strange problem. on one of my php pages, i'm using a mssql database. the problem wasn't connecting buut after it i tried this:
    Code:
      $id = mssql_connect($server.",1433",$user,$pw);
      
      mssql_select_db($db,$id);
      
      $query = mssql_query("SELECT DISTINCT name FROM sys.Tables");
      $tables = mssql_fetch_array($query);
      
      var_dump($tables);
    everything looks normal and it works fine as long as the database i select contains more then one table (when the query returns more then one record) or when i return more then one field. but when i dont, and the database only has one table. var dump outputs the same record twice.

    also, when i execute the query in sql management studio 2005, it only shows 1 record.

    it's easy enough to solve this, but i just want to know if i'm doing something wrong or if this is a bug in php?
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    #2
    seems like a bit of both. i've found out that mssql_fetch_arr ay will always return both an associative value and and an indexed value. therefor there are 2 records while there's only one in sql-server.

    problem solved by changing mssql_fetch_arr ay to mssql_fetch_ass oc. this only returns the associative value.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      As the second parameter to mssql_fetch_arr ay() you can give, I think, MSSQL_ASSOC, MSSQL_NUM, and it defaults to MSSQL_BOTH - the same behaviour as mysql_fetch_arr ay().

      Comment

      Working...