<?php $conn = mysql_connect('localhost','root',''); if($conn){ // echo '连接成功!'; mysql_select_db('test',$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 '失败!'; } ?>
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.