---
title: "初学php摘要(一)"
author: "eneve520"
date: "2009-09-07T15:39:27Z"
tags: []
slug: "php"
draft: false
lastmod: "2009-09-08T18:27:30Z"
id: 464075
url: "https://eneve520.iteye.com/blog/464075"
---

1.通过php链接mySql数据库

    

&lt;?  
//定义 变量 hello  
  $hello = "HelloWorld!&lt;br&gt;";  
  //输出变量hello  
  echo $hello;  
  //连接数据库  
 $dbconnection = mysql\_connect("localhost","root","lin");  
 //选择表单  
   mysql\_select\_db("test");  
   //设置编码 处理中文  
   mysql\_query("set names 'gbk'");  
  //执行sql语句 保存在变量rs\_users中  
  $rs\_users = mysql\_query("select * from userInfo",$dbconnection);  
  //统计查询胡结果有多少条记录 返回值保存在rs\_count 中  
  $rs\_count= mysql\_numrows($rs\_users);  
  echo $rs\_count;  
  //定义数组变量  
  $rs\_array = array();  
  //for循环输出 每一条记录  
  for ($i=0 ; $i &lt; $rs\_count ;$i++){     
   echo " i come to here ";  
   $rs\_array = mysql\_fetch\_array($rs\_users);  
   echo $rs\_array\[0].$rs\_array\[1] ;  
   echo "&lt;br&gt;";  
  }

//while循环用法  
// while($rs\_array =mysql\_fetch\_array($rs\_users)){    
  //数组变量接受每一条记录  
  //输出每一条记录的 每一字段的值  
 // echo $rs\_array\['user\_id'].$rs\_array\["user\_name"] ;  
// }  
?&gt;