php页面链接数据库 php7链接数据库( 三 )


private
$db_pwd;
//数据库密码
private
$db_database;
//数据库名
private
$conn;
//数据库连接标识;
private
$sql;
//sql执行的语句
private
$result;
//query的资源标识符
private
$coding;
//数据库编码,gbk,utf8,gb2312
private
$show_error
=
true;
//本地调试使用,打印错误
public
function
__construct($db_host,
$db_user,
$db_pwd,
$db_database,
$coding)
{
$this-db_host
=
$db_host;
$this-db_user
=
$db_user;
$this-db_pwd
=
$db_pwd;
$this-db_database
=
$db_database;
$this-coding
=
$coding;
$this-connect();
}
private
function
connect()
{
$this-conn
=
@mysql_connect($this-db_host,
$this-db_user,
$this-db_pwd);
if
(!$this-conn)
{
//show_error开启时,打印错误
if
($this-show_error)
{
$this-show_error('错误提示:链接数据库失败!');
}
}
if
(!@mysql_select_db($this-db_database,
$this-conn))
{
//打开数据库失败
if
($this-show_error)
{
$this-show_error('错误提示:打开数据库失败!');
}
}
if
(!@mysql_query("set
names
$this-coding"))
{
//设置编码失败
if
($this-show_error)
{
$this-show_error('错误提示:设置编码失败!');
}
}
}
}
php页面链接数据库的介绍就聊到这里吧 , 感谢你花时间阅读本站内容 , 更多关于php7链接数据库、php页面链接数据库的信息别忘了在本站进行查找喔 。

推荐阅读