Kurashu
02-20-2005, 10:42 PM
I'd like some opinions on this class I constructed for use with PostGres. Also, if any of you could give me some help on caching connections so a new one doesn't have be made if it is already in use (unless you are using the force new connection) and the query logging function (which doesn't seem to want to log).
I'm working on some documentation for this too. I appreciate your feedback.
Edit: Fixed errors in the query function, as well as removed a useless field in total_items and fixed the label for the dropdown function.
<?php
class postclass
{
//private functions and vars
private $host;
private $port;
private $database;
private $username;
private $password;
private $conns; //for future cache use
private function make_conn_string($host, $port, $dbname, $user, $pass)
{
$conn = sprintf("%s%s%s%s%s", (empty($host) ? '' : 'host=' . $host), (empty($port) ? '' : ' post=' . $port), (empty($dbname) ? '' : ' dbname=' . $dbname), (empty($user) ? '' : ' user=' . $user), (empty($host) ? '' : ' password=' . $pass));
$this->conns[] = $conn;
return $conn;
}
private function safe_query($query)
{
if ($query{-1} != ';')
{ $query .= ';'; }
if(!get_magic_quotes_gpc())
{ $query = addslashes(htmlspecialchars(trim($query))); }
else { $query = htmlspecialchars(trim($query)); }
return $query;
}
private function log_query($query, $file)
{
if(file_exists($file))
{ $fp = fopen($file, 'a'); }
else
{ $fp = fopen($file, 'x'); }
if($fp === true)
{
$date = date('mdy', filemtime($file));
flock($fp, LOCK_EX);
if(!(date('mdy') == $date))
{
fwrite($fp, '<strong>Queries for:' . $date . '</strong>' . "\n\r" . '<hr>' );
}
fwrite($fp, $query . "<br />\n\r" . 'Excuted At: ' . date('H:i:s') . "<br /><br />\n\r");
flock($fp, LOCK_UN);
fclose($fp);
return true;
}
else {return false; }
}
//protected functions and variables
protected $errors;
//public functions and variables
public $limit;
public $limit_array;
public $order_array;
public $arrange_array;
public $log_file;
public $debug;
function __construct($host, $port, $db, $user, $pass, $log, $limit=20)
{
if($this->debug) { echo '<!-- Starting a new PostGreSQL Class -->'; }
$this->host = $host;
$this->port = $port;
$this->database = $db;
$this->username = $user;
$this->password = $pass;
$this->order_array = array('ASC', 'DESC');
$this->limit_array = array('max' => 100, 'min' => 1);
$this->limit = $limit;
if(!empty($log) && file_exists($log))
{ $this->log_file = $log; }
$this->errors = array();
$this->conns = array();
}
function dconnect()
{
$error = "Couldn't connect to the PostGreSQL Database " . $this->database . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($this->host, $this->port, $this->database, $this->username, $this->password);
return pg_connect($conn) or die($this->errors($error, true));
}
function pdconnect()
{
$error = "Couldn't connect to the PostGreSQL Database " . $this->database . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($this->host, $this->port, $this->database, $this->username, $this->password);
return pg_pconnect($conn) or die($this->errors($error, true));
}
function connect($host, $port, $db, $user, $pass)
{
$error = "Couldn't connect to the PostGreSQL Database " . $db . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($host, $port, $db, $user, $pass);
return pg_connect($conn) or die($this->errors($error, true));
}
function pconnect($host, $port, $db, $user, $pass)
{
$error = "Couldn't connect to the PostGreSQL Database " . $db . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($host, $port, $db, $user, $pass);
return pg_pconnect($conn) or die($this->errors($error, true));
}
function close($sess)
{
$error = "Couldn't close the connection. Perhaps this connection wasn't opened?";
pg_close($sess) or die($this->errors($error . pg_last_error(), true));
}
function errors($msg, $echo)
{
$this->errors['postgres'][] = $msg;
if ($echo) { return $msg; }
return true;
}
function dump_errors()
{
$error = '<div class="errors">' . "\n\r";
$error .= '<span>PostClass Errors Dump</span>' . "\n\r";
$error .= '<ul>' . "\n\r";
foreach($this->errors['postgres'] as $v)
{ $error .= '<li>' . $v . '</li>' . "\n\r"; }
$error .= '</ul>' . "\n\r";
$error .= '</div>' . "\n\r";
return $error;
}
function query($query, $log=true)
{
if (empty($query)) { $this->errors('The query is empty. ($this->query())', false); return false;}
$query = $this->safe_query($query);
$sql = pg_query($query) or die($this->errors("The query failed to send. " . '<br />' . "\n\r" . pg_last_error() . '<br />' . "\n\r" . $query, true));
if($log && isset($this->log_file) )
{
$bool = $this->log_query($query, $this->log_file);
if($bool === false)
{
if(!file_exists($this->log_file)) { $error = 'The File Doesn\'t Exists.'; }
$error = sprintf("The query failed to be logged. %s", ((empty($error)) ? '' : '<br />' . "\n\r" . $error));
$this->errors($error, false);
}
}
return $sql;
}
function total_items($table)
{
if (empty($table)) { die($this->errors("You need to input a table name.",1)); }
$query = sprintf("SELECT * FROM %s", $table);
$con = pg_num_rows($this->query($query));
return $con;
}
function get_fields($table)
{
if(empty($table)) { $this->errors('Table must be declared in function get_fields', false); return false; }
$sql = $this->query(sprintf("SELECT * FROM %s LIMIT 1", $table));
$i = pg_num_fields($sql);
for ($j = 0; $j < $i; $j++)
{
$fields[$j] = pg_field_name($sql, $j);
}
return $fields;
}
function get_types($table)
{
if(empty($table)) { $this->errors('Table must be declared in function get_types', false); return false; }
$sql = $this->query(sprintf("SELECT * FROM %s LIMIT 1", $table));
$i = pg_num_fields($sql);
for ($j = 0; $j < $i; $j++)
{
$fields[$j] = pg_field_type($sql, $j);
}
return $fields;
}
function build_form($table, $ignore='id', $fields=false, $labels=true, $method='post', $action='')
{
if(empty($table)) { $this->errors('Table must be declared in function build_form', false); return false; }
$names = $this->get_fields($table);
$types = $this->get_types($table);
$count = count($names);
for($i=0; $i < $count; $i++){
for($x=0; $x < $count; $x++){
if($x == $i)
{
if ( is_array($ignore) && in_array($names[$i], $ignore)) {}
elseif ($names[$i] == $ignore) {}
else
{
if ($types[$x] == 'text') { $total[] = array('name' => $names[$i], 'type' => 'textarea'); }
else { $total[] = array('name' => $names[$i], 'type' => 'text'); }
}
}
}
}
if($fields == false)
{
$form = sprintf('<form method="%s" action="%s">' . "\n\r", $method, $action);
$form .= '<div class="form">';
foreach($total as $v)
{
if($labels) { $input = '<label for="lab_%1$s">%1$s</label>'; }
if ($v['type'] == 'text') {$input .= '<input type="text" name="%1$s" id="lab_%1$s" /><br />' . "\n\r"; }
elseif ($v['type'] == 'textarea') {$input .= '<textarea name="%1$s" id="lab_%1$s" rows="10" cols="60"></textarea><br />' . "\n\r"; }
$form .= sprintf($input, $v['name']);
unset($input);
}
$form .= '<input type="submit" value="Submit" /> ' . "\n\r";
$form .= '<input type="reset" value="Reset" /> ' . "\n\r";
$form .= '</div>' . "\n\r";
$form .= '</form>';
}
else
{
foreach($total as $v)
{
if($labels) { $input = '<label for="lab_%1$s">%1$s</label>'; }
if ($v['type'] == 'text') {$input .= '<input type="text" name="%1$s" id="lab_%1$s" /><br />' . "\n\r"; }
elseif ($v['type'] == 'textarea') {$input .= '<textarea name="%1$s" id="lab_%1$s" rows="10" cols="60"></textarea><br />' . "\n\r"; }
$form .= sprintf($input, $v['name']);
unset($input);
}
}
return $form;
}
function build_dropdown($table, $name='select', $value='id', $show='name', $label=false, $blank=false, $extras=false)
{
if (empty($table)) { $this->errors('$table needs to be set in function build_dropdown', false); return false; }
$query = sprintf('SELECT %s AS value, %s AS show FROM %s', $value, $show, $table);
$query = $this->query($query);
if($labels) { $select = '<label for="%1$s">' . $label . '</label>'; }
$select .= sprintf('<select name="%1$s" id="%1$s"%1$s>' . "\n\r", $name, ($extras ? ' ' . $extras : ''));
if($blank) { $select .= '<option selected="selected"></option>' . "\n\r"; }
while($row = pg_fetch_array($query, NULL, PGSQL_ASSOC))
{
$select .= sprintf('<option value="%s">%s</option>' . "\n\r", $row['value'], $row['show']);
}
$select .= '</select>';
return $select;
}
function array_to_fields($afields, $usekeys=false)
{
if(!is_array($afields)) { $this->errors('$afields MUST be an array', false); return false;}
$count = count($afields);
$x = 1;
if($usekeys)
{
foreach($afields as $as=>$fieldname)
{
$fields .= $fieldname . ' AS ' . $as;
if(!($x == $count)) { $fields .= ', '; }
else { $fields .= ' '; }
++$x;
}
}
else
{
foreach ($afields as $fieldname)
{
$fields .= $fieldname;
if(!($x == $count)) { $fields .= ', '; }
else { $fields .= ' '; }
++$x;
}
}
return $fields;
}
function build_select($args, $usekeys=false)
{
if(!is_array($args)) { $this->errors('$args must be an array in fcuntion build_select_array', false); return false; }
if (!$args['fields']) { $this->errors('$args[\'fields\'] must be set in fcuntion build_select_array', false); return false; }
if (!$args['table']) { $this->errors('$args[\'table\'] must be set in fcuntion build_select_array', false); return false; }
if(is_array($args['fields'])) { $args['fields'] = $this->array_to_fields($args['fields'], $usekeys); }
if ($args['order']) { $args['order'] = $this->order($args['order'], $args['arrange'], $this->arrange_array[0]); }
if ($args['limit']) { $args['limit'] = ' LIMIT ' . $this->fix_number($args['limit'], $this->limit_array['max'], $this->limit_array['min']); }
if ($args['limit'] && $args['page']) { $args['limit'] .= ' OFFSET ' . $this->offset($args['page'], $args['table']); }
if ( !($args['limit'] && $args['page']) && ($args['limit'] && $args['offset']) ) { $args['limit'] .= ' OFFSET ' . $args['offset']; }
$query = sprintf("SELECT %s FROM %s%s%s%s%s%s",
$args['fields'],
$args['table'],
(($args['where']) ? ' WHERE ' . $args['where'] : ''),
(($args['group']) ? ' GROUP BY ' . $args['group'] : '' ),
(($args['having']) ? ' HAVING ' . $args['having'] : '' ),
(($args['order']) ? ' ORDER BY ' . $args['order'] : ''),
(($args['limit']) ? ' ' . $args['limit'] : ''));
return $query;
}
function fix_number($number, $max, $min=1)
{
if($max <= $min)
{ list($max, $min) = array($min, $max); }
if($max <= $min)
{
return $max;
}
switch($number)
{
case !(is_numeric($number)):
case ($number <= $min):
case empty($number):
$number = $min;
break;
case ($number >= $max):
$number = $max;
break;
default:
$number = $number;
break;
}
return $number;
}
function fix_page($page=1, $table)
{
$total = $this->total_items($table);
$limit = $this->fix_number($this->limit, $this->limit_array['max'], $this->limit_array['min']);
$page = $this->fix_number($page, (ceil($total / $limit)), 1);
return $page;
}
function fix_order($order)
{
$order = strtoupper($order);
if (!(isset($this->order_array[$order]) || in_array($order, $this->order_array)))
{ $order = 'ASC'; }
return $order;
}
function fix_arrange($arrange, $default)
{
if (!(isset($this->arrange_array[$arrange]) || in_array($arrange, $this->arrange_array)))
{ $arrange = $default; }
return $arrange;
}
function order($order, $arrange, $default)
{
$arrange = $this->fix_arrange($arrange, $default);
$order = $this->fix_order($order);
$arrange .= ' ' . $order;
return $arrange;
}
function offset($page=1, $table)
{
$limit = $this->fix_number($this->limit, $this->limit_array['max'], $this->limit_array['min']);
$page = $this->fix_page($page, $table);
$offset = ($limit * ($page - 1));
return $offset;
}
}
?>
I'm working on some documentation for this too. I appreciate your feedback.
Edit: Fixed errors in the query function, as well as removed a useless field in total_items and fixed the label for the dropdown function.
<?php
class postclass
{
//private functions and vars
private $host;
private $port;
private $database;
private $username;
private $password;
private $conns; //for future cache use
private function make_conn_string($host, $port, $dbname, $user, $pass)
{
$conn = sprintf("%s%s%s%s%s", (empty($host) ? '' : 'host=' . $host), (empty($port) ? '' : ' post=' . $port), (empty($dbname) ? '' : ' dbname=' . $dbname), (empty($user) ? '' : ' user=' . $user), (empty($host) ? '' : ' password=' . $pass));
$this->conns[] = $conn;
return $conn;
}
private function safe_query($query)
{
if ($query{-1} != ';')
{ $query .= ';'; }
if(!get_magic_quotes_gpc())
{ $query = addslashes(htmlspecialchars(trim($query))); }
else { $query = htmlspecialchars(trim($query)); }
return $query;
}
private function log_query($query, $file)
{
if(file_exists($file))
{ $fp = fopen($file, 'a'); }
else
{ $fp = fopen($file, 'x'); }
if($fp === true)
{
$date = date('mdy', filemtime($file));
flock($fp, LOCK_EX);
if(!(date('mdy') == $date))
{
fwrite($fp, '<strong>Queries for:' . $date . '</strong>' . "\n\r" . '<hr>' );
}
fwrite($fp, $query . "<br />\n\r" . 'Excuted At: ' . date('H:i:s') . "<br /><br />\n\r");
flock($fp, LOCK_UN);
fclose($fp);
return true;
}
else {return false; }
}
//protected functions and variables
protected $errors;
//public functions and variables
public $limit;
public $limit_array;
public $order_array;
public $arrange_array;
public $log_file;
public $debug;
function __construct($host, $port, $db, $user, $pass, $log, $limit=20)
{
if($this->debug) { echo '<!-- Starting a new PostGreSQL Class -->'; }
$this->host = $host;
$this->port = $port;
$this->database = $db;
$this->username = $user;
$this->password = $pass;
$this->order_array = array('ASC', 'DESC');
$this->limit_array = array('max' => 100, 'min' => 1);
$this->limit = $limit;
if(!empty($log) && file_exists($log))
{ $this->log_file = $log; }
$this->errors = array();
$this->conns = array();
}
function dconnect()
{
$error = "Couldn't connect to the PostGreSQL Database " . $this->database . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($this->host, $this->port, $this->database, $this->username, $this->password);
return pg_connect($conn) or die($this->errors($error, true));
}
function pdconnect()
{
$error = "Couldn't connect to the PostGreSQL Database " . $this->database . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($this->host, $this->port, $this->database, $this->username, $this->password);
return pg_pconnect($conn) or die($this->errors($error, true));
}
function connect($host, $port, $db, $user, $pass)
{
$error = "Couldn't connect to the PostGreSQL Database " . $db . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($host, $port, $db, $user, $pass);
return pg_connect($conn) or die($this->errors($error, true));
}
function pconnect($host, $port, $db, $user, $pass)
{
$error = "Couldn't connect to the PostGreSQL Database " . $db . ". Please contact the adminastrator or webmaster.";
$conn = $this->make_conn_string($host, $port, $db, $user, $pass);
return pg_pconnect($conn) or die($this->errors($error, true));
}
function close($sess)
{
$error = "Couldn't close the connection. Perhaps this connection wasn't opened?";
pg_close($sess) or die($this->errors($error . pg_last_error(), true));
}
function errors($msg, $echo)
{
$this->errors['postgres'][] = $msg;
if ($echo) { return $msg; }
return true;
}
function dump_errors()
{
$error = '<div class="errors">' . "\n\r";
$error .= '<span>PostClass Errors Dump</span>' . "\n\r";
$error .= '<ul>' . "\n\r";
foreach($this->errors['postgres'] as $v)
{ $error .= '<li>' . $v . '</li>' . "\n\r"; }
$error .= '</ul>' . "\n\r";
$error .= '</div>' . "\n\r";
return $error;
}
function query($query, $log=true)
{
if (empty($query)) { $this->errors('The query is empty. ($this->query())', false); return false;}
$query = $this->safe_query($query);
$sql = pg_query($query) or die($this->errors("The query failed to send. " . '<br />' . "\n\r" . pg_last_error() . '<br />' . "\n\r" . $query, true));
if($log && isset($this->log_file) )
{
$bool = $this->log_query($query, $this->log_file);
if($bool === false)
{
if(!file_exists($this->log_file)) { $error = 'The File Doesn\'t Exists.'; }
$error = sprintf("The query failed to be logged. %s", ((empty($error)) ? '' : '<br />' . "\n\r" . $error));
$this->errors($error, false);
}
}
return $sql;
}
function total_items($table)
{
if (empty($table)) { die($this->errors("You need to input a table name.",1)); }
$query = sprintf("SELECT * FROM %s", $table);
$con = pg_num_rows($this->query($query));
return $con;
}
function get_fields($table)
{
if(empty($table)) { $this->errors('Table must be declared in function get_fields', false); return false; }
$sql = $this->query(sprintf("SELECT * FROM %s LIMIT 1", $table));
$i = pg_num_fields($sql);
for ($j = 0; $j < $i; $j++)
{
$fields[$j] = pg_field_name($sql, $j);
}
return $fields;
}
function get_types($table)
{
if(empty($table)) { $this->errors('Table must be declared in function get_types', false); return false; }
$sql = $this->query(sprintf("SELECT * FROM %s LIMIT 1", $table));
$i = pg_num_fields($sql);
for ($j = 0; $j < $i; $j++)
{
$fields[$j] = pg_field_type($sql, $j);
}
return $fields;
}
function build_form($table, $ignore='id', $fields=false, $labels=true, $method='post', $action='')
{
if(empty($table)) { $this->errors('Table must be declared in function build_form', false); return false; }
$names = $this->get_fields($table);
$types = $this->get_types($table);
$count = count($names);
for($i=0; $i < $count; $i++){
for($x=0; $x < $count; $x++){
if($x == $i)
{
if ( is_array($ignore) && in_array($names[$i], $ignore)) {}
elseif ($names[$i] == $ignore) {}
else
{
if ($types[$x] == 'text') { $total[] = array('name' => $names[$i], 'type' => 'textarea'); }
else { $total[] = array('name' => $names[$i], 'type' => 'text'); }
}
}
}
}
if($fields == false)
{
$form = sprintf('<form method="%s" action="%s">' . "\n\r", $method, $action);
$form .= '<div class="form">';
foreach($total as $v)
{
if($labels) { $input = '<label for="lab_%1$s">%1$s</label>'; }
if ($v['type'] == 'text') {$input .= '<input type="text" name="%1$s" id="lab_%1$s" /><br />' . "\n\r"; }
elseif ($v['type'] == 'textarea') {$input .= '<textarea name="%1$s" id="lab_%1$s" rows="10" cols="60"></textarea><br />' . "\n\r"; }
$form .= sprintf($input, $v['name']);
unset($input);
}
$form .= '<input type="submit" value="Submit" /> ' . "\n\r";
$form .= '<input type="reset" value="Reset" /> ' . "\n\r";
$form .= '</div>' . "\n\r";
$form .= '</form>';
}
else
{
foreach($total as $v)
{
if($labels) { $input = '<label for="lab_%1$s">%1$s</label>'; }
if ($v['type'] == 'text') {$input .= '<input type="text" name="%1$s" id="lab_%1$s" /><br />' . "\n\r"; }
elseif ($v['type'] == 'textarea') {$input .= '<textarea name="%1$s" id="lab_%1$s" rows="10" cols="60"></textarea><br />' . "\n\r"; }
$form .= sprintf($input, $v['name']);
unset($input);
}
}
return $form;
}
function build_dropdown($table, $name='select', $value='id', $show='name', $label=false, $blank=false, $extras=false)
{
if (empty($table)) { $this->errors('$table needs to be set in function build_dropdown', false); return false; }
$query = sprintf('SELECT %s AS value, %s AS show FROM %s', $value, $show, $table);
$query = $this->query($query);
if($labels) { $select = '<label for="%1$s">' . $label . '</label>'; }
$select .= sprintf('<select name="%1$s" id="%1$s"%1$s>' . "\n\r", $name, ($extras ? ' ' . $extras : ''));
if($blank) { $select .= '<option selected="selected"></option>' . "\n\r"; }
while($row = pg_fetch_array($query, NULL, PGSQL_ASSOC))
{
$select .= sprintf('<option value="%s">%s</option>' . "\n\r", $row['value'], $row['show']);
}
$select .= '</select>';
return $select;
}
function array_to_fields($afields, $usekeys=false)
{
if(!is_array($afields)) { $this->errors('$afields MUST be an array', false); return false;}
$count = count($afields);
$x = 1;
if($usekeys)
{
foreach($afields as $as=>$fieldname)
{
$fields .= $fieldname . ' AS ' . $as;
if(!($x == $count)) { $fields .= ', '; }
else { $fields .= ' '; }
++$x;
}
}
else
{
foreach ($afields as $fieldname)
{
$fields .= $fieldname;
if(!($x == $count)) { $fields .= ', '; }
else { $fields .= ' '; }
++$x;
}
}
return $fields;
}
function build_select($args, $usekeys=false)
{
if(!is_array($args)) { $this->errors('$args must be an array in fcuntion build_select_array', false); return false; }
if (!$args['fields']) { $this->errors('$args[\'fields\'] must be set in fcuntion build_select_array', false); return false; }
if (!$args['table']) { $this->errors('$args[\'table\'] must be set in fcuntion build_select_array', false); return false; }
if(is_array($args['fields'])) { $args['fields'] = $this->array_to_fields($args['fields'], $usekeys); }
if ($args['order']) { $args['order'] = $this->order($args['order'], $args['arrange'], $this->arrange_array[0]); }
if ($args['limit']) { $args['limit'] = ' LIMIT ' . $this->fix_number($args['limit'], $this->limit_array['max'], $this->limit_array['min']); }
if ($args['limit'] && $args['page']) { $args['limit'] .= ' OFFSET ' . $this->offset($args['page'], $args['table']); }
if ( !($args['limit'] && $args['page']) && ($args['limit'] && $args['offset']) ) { $args['limit'] .= ' OFFSET ' . $args['offset']; }
$query = sprintf("SELECT %s FROM %s%s%s%s%s%s",
$args['fields'],
$args['table'],
(($args['where']) ? ' WHERE ' . $args['where'] : ''),
(($args['group']) ? ' GROUP BY ' . $args['group'] : '' ),
(($args['having']) ? ' HAVING ' . $args['having'] : '' ),
(($args['order']) ? ' ORDER BY ' . $args['order'] : ''),
(($args['limit']) ? ' ' . $args['limit'] : ''));
return $query;
}
function fix_number($number, $max, $min=1)
{
if($max <= $min)
{ list($max, $min) = array($min, $max); }
if($max <= $min)
{
return $max;
}
switch($number)
{
case !(is_numeric($number)):
case ($number <= $min):
case empty($number):
$number = $min;
break;
case ($number >= $max):
$number = $max;
break;
default:
$number = $number;
break;
}
return $number;
}
function fix_page($page=1, $table)
{
$total = $this->total_items($table);
$limit = $this->fix_number($this->limit, $this->limit_array['max'], $this->limit_array['min']);
$page = $this->fix_number($page, (ceil($total / $limit)), 1);
return $page;
}
function fix_order($order)
{
$order = strtoupper($order);
if (!(isset($this->order_array[$order]) || in_array($order, $this->order_array)))
{ $order = 'ASC'; }
return $order;
}
function fix_arrange($arrange, $default)
{
if (!(isset($this->arrange_array[$arrange]) || in_array($arrange, $this->arrange_array)))
{ $arrange = $default; }
return $arrange;
}
function order($order, $arrange, $default)
{
$arrange = $this->fix_arrange($arrange, $default);
$order = $this->fix_order($order);
$arrange .= ' ' . $order;
return $arrange;
}
function offset($page=1, $table)
{
$limit = $this->fix_number($this->limit, $this->limit_array['max'], $this->limit_array['min']);
$page = $this->fix_page($page, $table);
$offset = ($limit * ($page - 1));
return $offset;
}
}
?>