Jump to content


Photo

problem using "SELECT *" with mssql DB


  • Please log in to reply
2 replies to this topic

#1 nitrox007

nitrox007
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 October 2006 - 08:00 PM

If I use this code I get nothing:
<html>
<head>
  <title>Wines</title>
</head>
<body><pre>

<?php
   // (1) Open the database connection and select the
   // winestore
   $connection = mssql_connect('localhost', 'usr', 'pass');
   mssql_select_db("mydb", $connection);

   // (2) Run the query on the winestore through the
   // connection
   $result = mssql_query("select * from table1",
                          $connection);

   // (3) While there are still rows in the result set
   while ($row = mssql_fetch_row($result))
   {
      // (4) Print out each attribute in the row
      for ($i=0; $i<mssql_num_fields($result); $i++)
         echo $row[$i] . " ";

      // Print a carriage return to neaten the output
      echo "\n";
   }

   // (5) Close the database connection
   mssql_close($connection);
?>
</pre>
</body>
</html>

but if I select a particular column then it works

<html>
<head>
  <title>Wines</title>
</head>
<body><pre>

<?php
   // (1) Open the database connection and select the
   // winestore
   $connection = mssql_connect('localhost', 'usr', 'pass');
   mssql_select_db("mydb", $connection);

   // (2) Run the query on the winestore through the
   // connection
   $result = mssql_query("select id from table1",
                          $connection);

   // (3) While there are still rows in the result set
   while ($row = mssql_fetch_row($result))
   {
      // (4) Print out each attribute in the row
      for ($i=0; $i<mssql_num_fields($result); $i++)
         echo $row[$i] . " ";

      // Print a carriage return to neaten the output
      echo "\n";
   }

   // (5) Close the database connection
   mssql_close($connection);
?>
</pre>
</body>
</html>

Am I not able to use SELECT * in MSSQL? it works fine in query analyzer.  Am I missing something?

#2 MCP

MCP
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 31 October 2006 - 02:33 AM

It definitely should..

what do you get when you put a var_dump($row); or print_r($row); in the while loop? what's the value of mssql_num_fields($result)?

#3 nitrox007

nitrox007
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 31 October 2006 - 03:13 PM

I figured out what the problem was.  I had some 'ntext' fields that weren't coming through.  I changed these to varchar and problem solved.  the data contained in this field is just text to it worked fine.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users