zoukankan      html  css  js  c++  java
  • php示例代码之使用list函数和mysql_fetch_row函数

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    <?php
      //连接参数
      $host="localhost";
      $user="root";
      $pwd="111111";
      $db="test";
       
      $linkID =mysql_connect($host,$user,$pwd); //创建一个mysql连接
       
      if(!$linkID){
        echo "<font color='red'>unable to connect!</font>";
      }
       
      mysql_select_db($db)or die("unable to select database"); //选择一个数据库
       
      $SQL_SELECT_SYMBOLS="select * from symbols";
       
      $result=mysql_query($SQL_SELECT_SYMBOLS)or die("error in query :$query. ".mysql_errno()); //执行SQL语句
       
      if(mysql_num_rows($result)>0){
        echo '<table cellpadding="10" border="1">';
        echo '<tr><th>id</th><th>country</th><th>animal</th><th>cname</th></tr>';
         while(list($id,$country,$animal,$cname)=mysql_fetch_row($result)){
            echo "<tr>";
            echo "<td>".$id."</td>";
            echo "<td>".$country."</td>";
            echo "<td>".$animal."</td>";
            echo "<td>".$cname."</td>";
            echo "</tr>";
         }
         echo "</table>";
      }
      else{
        echo "记录未找到!";
      }
       
      mysql_free_result($result); //释放记录集所占用的内存
       
      mysql_close($linkID); //关闭数据库连接
    ?>

     

  • 相关阅读:
    什么是RUP
    oracle 导入导出
    jsp 标签
    java json 交互
    Spring MVC 学习过程遇到的问题
    Spring 与其他ORM 框架结合 作数据持久层解析 (转)
    Spring mvc 中快速获取request、reponse、session
    Spring 数据绑定
    spring mvc 请求对应控制器的解析策略配置
    spring 的几种注解
  • 原文地址:https://www.cnblogs.com/webenh/p/5655687.html
Copyright © 2011-2022 走看看