Home  >  Article  >  Backend Development  >  php connect to database

php connect to database

WBOY
WBOYOriginal
2016-08-08 09:19:13905browse
  <?php 

$conn = mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;&#39;);
if($conn){
	// echo &#39;连接成功!&#39;;
	mysql_select_db(&#39;test&#39;,$conn);
	$result = mysql_query("SELECT * FROM user");
	// $res_arr = mysql_fetch_array($result);           //获得一条数据信息
	// print_r($res_arr);
	// $res_arr1 = mysql_fetch_assoc($result);        //获的一条数据信息(键和值)
	// print_r($res_arr1);
	$count = mysql_num_rows($result);                 //获取数据的个数
	for(i = 0;i<$count;i++){
		print_r(mysql_fetch_assoc($result));
	}
}else{
	echo &#39;失败!&#39;;
}

?>

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces PHP to connect to the database, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn