db.class.php
Code: Select all
<?php
class mysql {
private $linkid;
private $host;
private $user;
private $password;
private $db;
// class constructor
function _construct($host, $user, $password, $db) {
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->db = $db;
}
// connect to the mysql server
function connect() {
try {
$this->linkid = @mysql_connect($this->host,$this->user,$this->password);
if (! $this->linkid)
throw new Exception("Could not connect to the MySQL server");
}
catch (Exception $e) {
die($e->getMessage());
}
}
function select() {
try {
if (! @mysql_select_db($this->db, $this->linkid))
throw new Exception("Could not connect to the database");
}
catch (Exception $e) {
die($e->getMessage());
}
}
}
?>
Code: Select all
<?
include "db.class.php";
$mysqldb = new mysql("localhost", "dbuser", "password","dbtable");
$mysqldb->connect();
$mysqldb->select();
?>