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

    <?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($obj=mysql_fetch_object($result)){
      	 	echo "<tr>";
      	 	echo "<td>".$obj->id."</td>";
      	 	echo "<td>".$obj->country."</td>";
      	    echo "<td>".$obj->animal."</td>";
      	    echo "<td>".$obj->cname."</td>";
      	 	echo "</tr>";
      	 }
      	 echo "</table>";
      }
      else{
      	echo "记录未找到!";
      }
      
      mysql_free_result($result); //释放记录集所占用的内存
      
      mysql_close($linkID); //关闭数据库连接
    ?>
    

  • 相关阅读:
    java 无符号byte转换
    MySQL分区总结
    eclipse @override注解出错
    git 利用hook 实现服务器自动更新代码
    Centos 安装mysql
    Centos Python3安装共存
    chromedriver 代理设置(账号密码)
    PyQt5整体介绍
    python图片云
    PyPt5 浏览器实例
  • 原文地址:https://www.cnblogs.com/yql1986/p/2098317.html
Copyright © 2011-2022 走看看