A simple MySql class. A lot of these things are already in the BetterPHP library, or similar things. I just tried building this myself as sort of a practice:
/* MySql class
*
* @created : 8.7.2011
* @function : simplify MySql queries
*/
class MySQL {
private $conn;
private $db;
private $username;
private $password;
private $host;
private $port;
public function __construct($host, $user, $pw, $db, $port = '3306') {
$this->username = $user;
$this->password = $pw;
$this->host = $host;
$this->port = $port;
$this->db = $db;
$this->conn = mysql_connect($this->host . ':' . $this->port, $this->username, $this->password);
mysql_select_db($this->db, $this->conn);
}
public function createDb($name) {
mysql_query("CREATE DATABASE {$name}",$this->conn);
}
public function freeResult($result) {
mysql_free_result($result);
}
public function close() {
mysql_close($this->conn);
}
public function query($query) {
mysql_query($query, $this->conn);
}
public function selectDb($name) {
mysql_select_db($name, $this->conn);
}
public function esc($str) {
$var = mysql_real_escape_string($str);
return $var;
}
}