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);
?>