class dbLink {
var $server; # server address
var $username; # username to connect with
var $password; # password to connect with
var $database; # name of database to use
var $connection; # database connection object
var $errors; # array to contain all errors encountered
# CONSTRUCTOR
function __construct($table_to_use) {
# If new connection does not specify which database to connect to, default to localhost.
switch($table_to_use){
default:
$mysql_server_ip = 'localhost';
break;
}
$mysql_db_name = 'facetime';
if($_COOKIE['power'] == 0){
# REGISTERED USER [2] || PAID USER [4] || RECRUITER [6]
# connect to database as normal account
$mysql_user = 'ft_user';
$mysql_password = 'password';
} else {
# GUESTS ||
# connect to database as guest account with only SELECT priviledges
$mysql_user = 'ft_guest';
$mysql_password = 'password';
}
$this->connect($mysql_server_ip, $mysql_user, $mysql_password, $mysql_db_name);
}
# Creates connection to database
function connect($server,$username,$password,$database){
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->connection = mysql_connect($this->server, $this->username, $this->password);
if (!$this->connection) { $this->errors[] = mysql_error(); }
else {
if(!mysql_select_db($database, $this->connection)){ $this->errors[] = mysql_error(); }
}
}
# Break connection to database
function disconnect() { }
# QUERIES
# This function is the base wrapper to pass any sql statement (insert / delete / select)
# Returns result object on success, or false on failure.
function query($sql) { if($result = mysql_query($sql, $this->connection)){ return $result; } else { return false; } }
# This function utilize the base db wrapper to execute select queries
# Return array of results on success to avoid user having to implement mysql_fetch calls. Return false on failure.
function select($sql) {
if($result = $this->query($sql)){
while($row = mysql_fetch_assoc($result)){ $result_array[] = $row; }
return $result_array;
} else {
$this->errors[] = mysql_error();
return false;
}
}
}