【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“dbconnection.php”一文,供大家参考学习
<?php
class classname
{
// 连接数据库属性
var $CONN = "";
//连接数据库的服务器
var $IPADD = "localhost";
//用户名
var $USER = "root";
//密码
var $PASS = "123456";
//数据库名
var $DBASE = "countdb";
function error($text)
{
$no = mysql_errno ();
$msg = my
sql_error ();
echo "[$text] ( $no : $msg) <br> \n";
exit ;
}
//初始化数据库连接
function init()
{
$ipadd = $this->IPADD;
$user = $this->USER;
$pass = $this->PASS;
$dbase = $this->DBASE;
$conn =
mysql_pconnect ($ipadd,$user,$pass);
if (!$conn)
{
$this->error ("没有连接到服务器");
}
if (!mysql_select_db($dbase))
{
$this->error ("连接数据库失败");
}
$this->CONN = $conn;
return true;
}
}