Created
August 21, 2015 11:16
-
-
Save BugBuster1701/f3efeb3cd47a592241b4 to your computer and use it in GitHub Desktop.
mysql_reconnect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://stackoverflow.com/a/11535487 | |
class databaseClass { | |
var $conn; | |
var $db; | |
public function __construct() { | |
$this->connect(); | |
} | |
public function connect() { | |
$this->conn = mysql_connect(DB_HOST, DB_USER, DB_PASS); | |
$this->db = mysql_select_db(DB_NAME, $this->conn); | |
} | |
public function disconnect() { | |
mysql_close($this->conn); | |
} | |
public function reconnect() { | |
$this->disconnect(); | |
$this->connect(); | |
} | |
public function queryCompanyExist($company) { | |
//auto reconnect if MySQL server has gone away | |
if (!mysql_ping($this->conn)) $this->reconnect(); | |
$query = "SELECT name FROM company WHERE name='$company'"; | |
$result = mysql_query($query); | |
if (!$result) print mysql_error() . "\r\n"; | |
return mysql_fetch_assoc($result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment