php连接MySQL数据库的实际操作步骤与代码


  本文标签:连接MySQL数据库

  以下的文章主要介绍的是php连接MySQL数据库的实际操作步骤以及对php连接MySQL数据库的时机应用代码的描述,下面就是对其相关内容的具体内容描述,希望会给你带来一些帮助在此方面  。

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

  PHP操作MySQL

  extension=php_MySQL.dll打开

  1. php 
  2. $servername = "127.0.0.1";  
  3. $username = "root";  
  4. $password = "123456";  
  5. $conn = MySQL_connect($servername, $username, $password);  

  建立MySQL连接

  1. if($conn) { 

  echo "连接MySQL数据库成功";

  1. }  
  2. //MySQL_select_db("easytoo"); 

  选择要连接的数据库

  或者

  1. MySQL_query("use easytoo",$conn); 

  选择要连接MySQL数据库

  1. MySQL_query("SET NAMES utf8");  
  2. $rs = MySQL_query("select id from et_category"); 

  查询获取一个数据集

  1. MySQL_num_rows($rs);  

  得到记录集总数

  1. while($row=mysql_fetch_array($rs))  

  循环数据集

  1. {  
  2. echo "$row[0]<br>";  
  3. }  
  4. mysql_free_result($rs);  

  释放rs

  1. mysql_close($conn); 

  关闭连接

  1. ?> 

  以上的相关内容就是对php连接MySQL数据库的介绍,望你能有所收获  。