- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
class Db {
private $where;
private $select = '*';
private $limit;
private $order_by;
private $query;
private $set;
private function query_string($table){
$query = ($this->query) ? $this->query : "SELECT $this->select FROM $table WHERE $this->where $this->order_by $this->limit";
return $query;
}
function query($text){
$this->query = $text;
return $this;
}
function where_text($text){
$operator = 'AND';
if (!$this->where){
$this->where = $text;
} else {
$this->where .= $operator." ".$text;
}
return $this;
}
function order_by_text($text){
if (!$this->order_by){
$this->order_by = ' ORDER BY '.$text;
} else {
$this->order_by .= ', '.$text;
}
}
function connect($host,$login_mysql,$password_mysql,$baza_name) {
$db = @mysql_connect("$host", "$login_mysql", "$password_mysql");
mysql_set_charset('utf8',$db);
if (!$db) exit("<p>Sorry, not available MySQL server</p>");
if (!@mysql_select_db($baza_name,$db)) exit("<p>Unfortunately, the database is not available</p>");
}
function select($column){
$this->select = $column;
return $this;
}
function limit($start,$count){
$this->limit = ' LIMIT '.$start.','.$count;
return $this;
}
function order_by($key){
if (is_array($key)){
foreach ($key as $column => $value){
if (!$this->order_by){
$this->order_by = ' ORDER BY '.$column.' '.$value;
} else {
$this->order_by .= ', '.$column.' '.$value;
}
}
} else {
if (!$this->order_by){
$this->order_by = ' ORDER BY '.$key;
} else {
$this->order_by .= ', '.$key;
}
}
return $this;
}
function where($key,$compare = '='){
$operator = 'AND';
if (is_array($key)){
foreach ($key as $column=>$value){
if (!$this->where){
$this->where = $column.$compare."'".$value."' ";
} else {
$this->where .= $operator." ".$column.$compare."'".$value."' ";
}
}
} else {
$key = explode(',',$key);
if (!$this->where){
$this->where = $key[0].$compare."'".$key[1]."' ";
} else {
$this->where .= $operator." ".$key[0].$compare."'".$key[1]."' ";
}
}
return $this;
}
function search($column,$search){
$operator = 'AND';
$search = strtr($search,array(" "=>" +"));
$search = '+'.$search;
$w = 'MATCH('.$column.") AGAINST('".$search."' IN BOOLEAN MODE)";
if (!$this->where){
$this->where = $w;
} else {
$this->where .= $operator." ".$w;
}
return $this;
}
function lines($table,$ext = true){
$msql_query = mysql_query($this->query_string($table));
$line = mysql_fetch_assoc($msql_query);