我有这个数据库类
function MySQLDB(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
/**
* Only query database to find out number of members
* when getNumMembers() is called for the first time,
* until then, default value set.
*/
$this->num_members = -1;
if(TRACK_VISITORS){
/* Calculate number of users at site */
$this->calcNumActiveUsers();
/* Calculate number of guests at site */
$this->calcNumActiveGuests();
}
}
我收到max_user_connections错误,只有12个用户登录。我看到这个脚本显示如果用户超出配额,则在用户之间切换。
ini_set('display_errors', '0');
$link = mysql_connect("localhost", "user", "pass");
if (mysql_errno() == 1040 OR mysql_errno() == 1203) {
define("DB_HOST", "some_ip:3306");//remote
define("DB_NAME", "db"); //database_name
define("DB_USER", "user"); //database user name
define("DB_PASSWORD","pass"); //database (user) password
}
else
{
define("DB_HOST", "localhost");
define("DB_NAME", "db_name2"); //database_name
define("DB_USER", "user"); //database user name
define("DB_PASSWORD","pass"); //database (user) password
}
ini_set('display_errors', '1');
//by feha at www.vision.to
有人能指出我如何将这个功能放入我的课程的正确方向。提前谢谢。
更新 如果出现错误,这是否可以重置$ this->连接到辅助用户?
function MySQLDB(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
if (mysql_errno() == 1040 OR mysql_errno() == 1203) {
$this->connection = mysql_connect(DB_SERVER, DB_SEC_USER, DB_SEC_PASS) or die(mysql_error());
}
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
/**
* Only query database to find out number of members
* when getNumMembers() is called for the first time,
* until then, default value set.
*/
$this->num_members = -1;
if(TRACK_VISITORS){
/* Calculate number of users at site */
$this->calcNumActiveUsers();
/* Calculate number of guests at site */
$this->calcNumActiveGuests();
}
}