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; }

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索