Mysqlhasgoneaway public function connect (){
If ($ this-> conn = "pconn "){
// Permanent link
$ This-> conn = mysql_pconnect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd );
} Else {
// Even if the link
$ This-> conn = mysql_connect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd );
}
If (! Mysql_select_db ($ this-> db_database, $ this-> conn )){
If ($ this-> show_error ){
$ This-> show_error ("database unavailable:", $ this-> db_database );
}
}
Mysql_query ("set names $ this-> coding ");
}
The above is the writing of database connections. how can I avoid errors? Are there other methods?
Reply to discussion (solution)
Ask the experts to give a method
The database connection times out or exceeds the non-operation timeout setting and is forcibly disconnected from the database. Another possibility is that the database is unstable. Persistent connections are not recommended ~~ We do not recommend that you obtain super-large data results at a time ~
function dbConnect($hostname,$username,$pass,$db_name,$pconnect = 0) { $func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect'; if(!$connect) { $connect = @$func($hostname,$username,$pass) or die("Mysql_Error : ".mysql_error()."
Mysql Error Num : ".mysql_errno().""); } @mysql_select_db($db_name, $connect) or die(" Mysql_Error : ".mysql_error()."
Mysql Error Num : ".mysql_errno().""); return $connect;}
We recommend that you close the connection to the database after the query is completed.