I'm trying to develop a global class for paging
Follow the code below:
class Pager {
private $Sql;
private $Limit;
private $ArgType;
private $Page;
private $Arguments;
private $ArgNumber;
private $Connect;
private $result=array();
public function setSql($Sql){
$this->Sql=$Sql;
return false;
}
public function setLimit($Limit){
$this->Limit=$Limit;
return false;
}
public function setArguments(){
$this->Arguments=func_get_args();
$this->ArgNumber=func_num_args();
return false;
}
public function setArgType($ArgType){
$this->ArgType=$ArgType;
return false;
}
public function setConnect($Connect){
$this->Connect=$Connect;
return false;
}
public function setPage($Page){
$this->Page= isset($Page)?$Page:1;
return false;
}
private function countRegister(){
$Pager = $this->Connect->prepare($this->Sql);
switch ($this->ArgNumber){
case 1:
$Pager->bind_param($this->ArgType,$this->Arguments[0]);
break;
case 2:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1]);
break;
case 3:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1],$this->Arguments[2]);
break;
case 4:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1],$this->Arguments[2],$this->Arguments[3]);
break;
case 5:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1],$this->Arguments[2],$this->Arguments[3],$this->Arguments[4]);
break;
}
$Pager->execute();
$Pager->store_result();
return $Pager->num_rows;
$Pager->close();
}
private function countPages($NumReg){
return ceil($NumReg/$this->Limit);
}
private function prevPage(){
if($this->Page>1)
return $this->Page-1;
else
return false;
}
private function nextPage(){
if($this->Page<$this->result['Pages'])
return $this->Page+1;
else
return false;
}
private function getStart(){
return ($this->Page-1)*$this->Limit;
}
public function execPager(){
$this->result['Pages'] = $this->countPages($this->countRegister());
$this->result['PrevPage'] = $this->prevPage();
$this->result['NextPage'] = $this->nextPage();
$this->result['Start'] = $this->getStart();
$this->result['Limit'] = $this->Limit;
return false;
}
public function getPager(){
return $this->result;
}
}
But in%% I do not see a mode of doing private function execPage()
with bind_param
that I get in function array
the only way was to use a case with predefined possibilities
Any suggestions on how to pass these parameters to the function and be able to do this?
I am using mysqli and the class is in the initial stage, in the function setArguments
I will pass N arguments and put the type of argument by function setArgument
being that it will be a setArgType
then I will put inside string
this way
$Pager->bind_param($this->setArgType, [Todos os N argumentos da setArguments]);