php连接数据库
php简单的连接数据库的代码
$host = "192.168.51.18:3306";
$root = "登录名称";
$password = "登录密码";
$dbname = "数据库名称";
$connect = mysql_connect($host,$root,$password,$dbname);
mysql_select_db("erp_database", $connect);//erp_database是库名
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
//这是查询
$sql="select * from erp_orders where erp_orders_id='1054639851'";
//添加
/$sql=”insert into ………….”;
$result = mysql_query($sql);
print_r(mysql_fetch_row($result));
while($row = mysql_fetch_array($result))
{
echo $row['erp_orders_id'] . " -->" . $row['buyer_name'];
echo "<br />";
}
mysql_connect()函数是连接数据库
mysql_select_db(‘库名’,mysql_connect(‘地址 ,‘name’,’password’,’库名’))
mysql_fetch_array()是将查询出来的值转化为数组。当用print_r()打印的时候是有数字和字段作为键,值是一样的。mysql_fetch_row()和mysql_fetch_array()的区别就是mysql_fetch_row()函数打印出来的键是数字没有字段作为键。
2.mysql_real_escape_string 转化为字符串。