PHP访问MySQL数据库
生活随笔
收集整理的這篇文章主要介紹了
PHP访问MySQL数据库
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
mysql_connect()??????? //連接MySQL服務(wù)器
mysql_select_db()????? //選擇數(shù)據(jù)庫文件
mysql_query()???????????? //執(zhí)行SQL語句
mysql_fetch_array()??? //從數(shù)組結(jié)果集中獲取信息
mysql_fetch_object()? ?//從結(jié)果集中獲取一行作為對象
mysql_fetch_row()????? //逐行獲取結(jié)果集中的每條記錄
mysql_num_rows()???? //獲取查詢結(jié)果集中的記錄數(shù)
------------------------------------------------------------------------------------------------------
插入信息
<?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);?>
?
?
總結(jié)
以上是生活随笔為你收集整理的PHP访问MySQL数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP页面间参数传递的四种方式
- 下一篇: linux下安装Apache,php,M