WebEnh

.net7 mvc jquery bootstrap json 学习中 第一次学PHP,正在研究中。自学进行时... ... 我的博客 https://enhweb.github.io/ 不错的皮肤:darkgreentrip,iMetro_HD
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

php示例代码之 使用PHP的MySQL标准函数

Posted on 2016-07-09 13:35  WebEnh  阅读(279)  评论(0编辑  收藏  举报
<?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($row=mysql_fetch_row($result)){
  	 	echo "<tr>";
  	 	echo "<td>".$row[0]."</td>";
  	 	echo "<td>".$row[1]."</td>";
  	        echo "<td>".$row[2]."</td>";
  	        echo "<td>".$row[3]."</td>";
  	 	echo "</tr>";
  	 }
  	 echo "</table>";
  }
  else{
  	echo "记录未找到!";
  }
  
  mysql_free_result($result); //释放记录集所占用的内存
  
  mysql_close($linkID); //关闭数据库连接
?>