PHP long-term database connection facilitates mysqlhasgoneaway
PHP takes a long time to connect to the database causing mysql has gone awaypublic 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”); } What is posted above is how to write a database connection. How can I write it without errors? Is there any other way? Share to: conn?==?” pconn”)?{ //permanent link $this->conn?=?mys…’ data-pics=”> ——Solution——————– 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; }
PHP long-term database connection facilitates mysqlhasgoneaway
PHP takes a long time to connect to the database causing mysql has gone awaypublic 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”); } What is posted above is how to write a database connection. How can I write it without errors? Is there any other way? Share to: conn?==?” pconn”)?{ //permanent link $this->conn?=?mys…’ data-pics=”> ——Solution——————– 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; }