美文网首页我爱编程
PHP数据库配置

PHP数据库配置

作者: 灰纸白字 | 来源:发表于2018-05-07 19:17 被阅读9次
PHP编码格式,防止乱码

header("Content-type:text/html;charset=utf-8");

定义数据库变量

$localhost = "localhost";//数据库的地址
$username = "root";//数据库用户名
$password = "root";//数据库密码
$database = "----";//数据库名

连接数据库

$con = @mysql_connect($localhost,$username,$password);

判断数据库是否连接正确

if(!$con){
die('数据库连接失败原因: ' . mysql_error());
}
$conn = @mysql_select_db($database,$con);
if(!$conn){
die('数据库访问失败原因: '.mysql_error());
}

相关文章

网友评论

    本文标题:PHP数据库配置

    本文链接:https://www.haomeiwen.com/subject/bgwvrftx.html