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


?>


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值