php查询MySQL数据

 <?php
      $link = mysql_connect('localhost', 'root', '123456')
      or die('Could not connect: ' . mysql_error());
      mysql_select_db('ruida') or die('Could not select database');

      // 执行 SQL 查询
      $query = 'SELECT * FROM product';
      $result = mysql_query($query) or die('Query failed: ' . mysql_error());

       // 用 HTML 显示结果
                 echo "<table>\n";
          while ($line = mysql_fetch_assoc($result)) {
                 echo "\t<tr>\n";
             foreach ($line as $col_value) {
                 echo "\t\t<td>$col_value</td>\n";
                              }
                 echo "\t</tr>\n";
                       }
                 echo "</table>\n";
                // 释放结果集
              mysql_free_result($result);
          // 关闭连接
              mysql_close($link);
  ?>             

posted on 2010-03-24 20:30  我们都一样  阅读(410)  评论(0)    收藏  举报

导航