600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > PHP访问MySQL数据库

PHP访问MySQL数据库

时间:2019-02-05 09:01:10

相关推荐

PHP访问MySQL数据库

mysql_connect() //连接MySQL服务器

mysql_select_db() //选择数据库文件

mysql_query() //执行SQL语句

mysql_fetch_array() //从数组结果集中获取信息

mysql_fetch_object() //从结果集中获取一行作为对象

mysql_fetch_row() //逐行获取结果集中的每条记录

mysql_num_rows() //获取查询结果集中的记录数

------------------------------------------------------------------------------------------------------

插入信息

<?php$con = mysql_connect("127.0.0.1","root","");if (!$con){die('Could not connect: ' . mysql_error());}echo "connect sucessed";mysql_select_db("info_db",$con);mysql_query("set names gb2312");$client_ip = $_GET['ip'];$computer_name = $_GET['computer_name'];$system_ver = $_GET['system_ver'];$user_name = $_GET['user_name'];$client_mark = $_GET['client_mark'];$first_online_time = $_GET['first_online_time'];$last_online_time = $_GET['last_online_time'];$sql = mysql_query("insert into client_list (ip,computer_name,system_ver,user_name,client_mark,first_online_time,last_online_time)values('$client_ip','$computer_name','$system_ver','$user_name','$client_mark','$first_online_time','$last_online_time')");//echo "<script>alert('add client sucessed')</script>";//mysql_free_result($sql);mysql_close($con);?>

查询信息

<?php$con = mysql_connect("127.0.0.1","root","");if (!$con){die('Could not connect: ' . mysql_error());}echo "connect sucessed";mysql_select_db("info",$con);$sql = mysql_query("SELECT * FROM client");$row=mysql_fetch_object($sql);if(!$row){echo "row is null";}do{printf("ip: %s\r\n",$row->IP);}while($row=mysql_fetch_object($sql));//echo "<script>alert('add client sucessed')</script>";//mysql_free_result($sql);mysql_close($con);?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。