В нормальном коде можно сделать вот так
Class SqlQuery(){
private $get;
private $q;
public function __construct($q){
$this->get=$_GET;
$this->q=$q;
}
public function query($q){
return
($q?)$q:$this->q.
$this->search().
$this->where().
$this->limit().
';';
}
private function search(){
if(isset($this->get['text'])) {
$text=mysqli::real_escape_string($this->get['text']);
return ' `text` like "%'.$text.'%"';
}
else
throw new _Exception();
}
private function where(){
if(isset($this->get['cat']))
return ' where `cat`='.mysqli::real_escape_string($this->get['cat']);
}
private function limit(){
return ' limit 0,20';
}
}
Ну или вроде того, поскольку это вообще пример.