Jump to content

problem using "SELECT *" with mssql DB


nitrox007

Recommended Posts

If I use this code I get nothing:
[code]
<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>
[/code]

but if I select a particular column then it works

[code]
<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>
[/code]

Am I not able to use SELECT * in MSSQL? it works fine in query analyzer.  Am I missing something?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.