PHP连接数据库代码

时间:2021-10-14 17:28:18
<?php
$db = @mysql_connect("localhost","root","root") or die("连接失败");
mysql_select_db("test",$db);
mysql_query("set names utf-8");
$password = md5("liuzhiqiang");
$regdate = time();
$sql = "insert into user2 values(null,'小1王','$password','123456@163.com',$regdate);";
if(!mysql_query($sql,$db)){
echo "添加数据失败:".mysql_error();
} else {
echo "添加数据成功!";
}
?>