Dbcore PHP

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

<?

php

define('dbcore_version','0.1');
define('OBJECT','OBJECT',true);
define('ARRAY_A','ARRAY_A',true);
define('ARRAY_N','ARRAY_N',true);
define('ERR','Your database specific php class file does not contain function ');

class dbCore {
//errors
public $show_errors = true;
public $captured_errors = array();
//log
public $num_queries = 0;
public $last_query = null;
public $last_error = null;
public $col_info = null;
//cache
public $cache_dir = false;
public $cache_queries = false;
public $cache_inserts = false;
public $use_disk_cache = false;
public $cache_timeout = 24; //hours

function __construct() {
echo " hi there.You are in dbcore.php :) ";
}

function connect() {
die(ERR . __FUNCTION__ ."()");
}

function select() {
die(ERR . __FUNCTION__ ."()");
}

function query() {
die(ERR . __FUNCTION__ ."()");
}

function register_error($err_str) {
$this->last_error = $err_str;
$this->captured_errors[] = array
(
'error_str' => $err_str,
'query' => $this->last_query
);
}

function show_errors() {
$this->show_errors = false;
}

function hide_errors() {
$this->show_errors = false;
}
function flush() {
$this->last_result = null;
$this->col_info = null;
$this->last_query = null;
$this->from_disk_cache = false;
}

function get_var($query=null, $col=0, $row=0) {


//log how the function was called
$this->func_call = "\$db->get_var(\"$query\",$col,$row)";
//perform the query
if ($query) {
$this->query($query);
}

if ( $this->last_result[$row] ) {
$values = array_values(get_object_vars($this-
>last_result[$row]));
}

return (isset($values[$col]) && $values[$col] !==


'')?$values[$col]:null;

function get_row($query=null, $output=OBJECT, $y=0) {


if ($query) {
$this->query($query);
}
if ($output == OBJECT) {
return $this->last_result[$y] ? $this->last_result[$y] : null;
}
if ($output == ARRAY_A) {
return $this->last_result[$y] ? get_object_vars($this-
>last_result[$y]) : null;
}
if ($output == ARRAY_N) {
return $this->last_result[$y] ?
array_values(get_object_vars($this->last_result[$y])) : null;
}
else {
echo "\$db->get_row(string query, output type, int offset) --
Output type must be one of: OBJECT, ARRAY_A, ARRAY_N";
}
}

function get_col($query=null, $col=0) {


if( $query ) {
$this->query($query);
}
for ($i=0; $i < count($this->last_result); $i++) {
$new_array[$i] = $this->get_var(null,$col,$i);
}
return $new_array;
}

function get_results($query=null, $output = OBJECT) {


if($query) {
$this->query($query);
}

if ($output == OBJECT) {
return $this->last_result;
}
elseif ($output == ARRAY_A || $output = ARRAY_N) {

if ($this->last_result) {
$i = 0;
foreach ($this->last_result as $row) {
$new_array[$i] = get_object_vars($row);
if ($output == ARRAY_N) {
$new_array[$i] = array_values($new_array[$i]);
}
$i++;
}
return $new_array;
}
else {
return null;
}
}
//else {
//echo " Invalid $output";
//}
}

function get_col_info($info_type='name',$col_offset=-1) {
if ($this->col_info) {
if ( $col_offset == -1) {
$i = 0;
foreach ($this->col_info as $col) {
$new_array[$i] = $col->{$info_type};
$i++;
}
return $new_array;
}
else {
return $this->col_info[$col_offset]->{$info_type};

}
}
else {
echo " There is no last query executed ";
}
}

function store_cache($query,$is_insert) {
}

function get_cache($query) {
}

function var_dump($mixed = '') {


}

function debug() {
}
}
?>

You might also like