<?php
########################################################################
# ---------- File developed by RĂºben Doi - hide@address.com ---------- #
# ----------------------- Created on - 01/2007 ----------------------- #
# -------------------------------------------------------------------- #
# --------------- Object Orientation for PHP - Classes --------------- #
########################################################################
# includes
include_once("conf.inc.php");
include_once(INCLUDES_PATH."messages.php");
# interface Class between php and Data Base Server
class conection{
# atributos da classe
var $file;
var $username;
var $password;
var $server;
var $database;
var $type;
var $conn;
var $db_selected;
var $result;
#metodos da classe
function conection(){
$this->username = _USERNAME;
$this->password = _PASSWORD;
$this->server = _SERVER;
$this->database = _DATABASE;
$this->type = _DB_TYPE;
}
# method to establish conection with the db server
function open_conn(){
switch ($this->type){
case "mysql":
$this->conn = mysql_connect($this->server, $this->username, $this->password);
if (!$this->conn) {
DieFriendly('Failed to connect: ' . mysql_error());
}
# selecting the data base
$this->db_selected = mysql_select_db($this->database, $this->conn);
break;
case "mssql":
# not implemented yet
break;
case "access":
# not implemented yet
break;
# if you have another type of db, just create a new case here.
}
}
# method to execute a sql comand
function executeQuery($Sql){
switch ($this->type){
case "mysql":
$this->result = mysql_query($Sql);
if (!$this->result) {
DieFriendly('Invalid Query : ' . mysql_error());
}
break;
case "mssql":
# not implemented yet
break;
case "access":
# not implemented yet
break;
# if you have other type of db, just create a new case here.
}
}
# method to finish the connection
function close_conn(){
switch ($this->type){
case "mysql":
mysql_close($this->conn);
break;
case "mssql":
# not implemented yet
break;
case "access":
# not implemented yet
break;
# if you have other type of db, just create a new case here.
}
}
# set user
function set_username($username){
$this->username = $username;
}
# returns user
function get_username(){
return $this->username;
}
# set password
function set_password($pass){
$this->password = $pass;
}
function get_password(){
return $this->password;
}
# set the path to the server
function set_server($server){
$this->server = $server;
}
# return the path to the server
function get_server(){
return $this->server;
}
# set the database name
function set_database($db){
$this->database = $db;
}
# return the database name
function get_database(){
return $this->database;
}
# set the type of db
function set_type($type){
$this->type = $type;
}
# return the type of db
function get_type(){
return $this->type;
}
}
?>