1. 授权
GRANT select,insert,delete,update ON mydb.* to tan IDENTIFIED by '123456';
2. 打开端口
1)关闭防火墙
chkconfig iptables off
service iptables stop
或
2)修改/etc/sysconfig/iptables 文件,加上
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
3. php代码
代码:
test.php
<?php
$db_host="192.168.1.2";
$db_user="tan";
$db_password="123456";
$db_name="mydb";
$company_table="company";
$link=mysql_connect($db_host,$db_user,$db_password) or die("连接数据库失败");
$db=mysql_select_db($db_name,$link);
$query="insert into $company_table (company) values ('tansf')";
$result=mysql_query($query);
$query="select * from $company_table";
$result=mysql_query($query);
$total=mysql_num_rows($result);
echo $total;
?>
访问 http://192.168.1.4/test.php
本文地址:http://com.8s8s.com/it/it25525.htm