PHP long-time connection database contributed to MySQL has gone away

Source: Internet
Author: User
PHP Long connection database caused MySQL has gone away
Public Function connect () {
if ($this->conn = = "Pconn") {
Permanent links
$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 affixed to the database connection of the writing, how can I write to do not appear errors? Is there any other way to do it?

Share to:


------Solution--------------------

{
$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

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.