Apache使用php查询MySQL数据库


数据库:

getAllPeopleBornAfter.php

[php]
  1. <?php  
  2.     mysql_connect("localhost","root","shiguang");    
  3.     mysql_select_db("student");    
  4.     $sql = "SELECT * FROM `student` WHERE `scores` > 90";  
  5.     $result=mysql_query($sql);   
  6.       
  7. // 浏览器使用   
  8.     while ($fields = mysql_fetch_row($result))  
  9.     {  
  10.         for ($i=0, $max=sizeof($fields); $i < $max$i++ )   
  11.         echo $fields[$i]."  ";  
  12.         echo "<br>";  
  13.     }  
  14.       
  15. /* 
  16. // 手机使用 
  17.     while($e=mysql_fetch_assoc($result))   
  18.         $output[]=$e;   
  19.     print(json_encode($output)); 
  20. */  
  21.     mysql_close();    
  22. ?>  

查询结果:


PS:都是很简单的东西,只是想边学习边做笔记。高手请绕道!

相关内容