I have the following class:
class BindParam{
private $values = array(), $types = '';
public function add( $type, &$value ){
$this->values[] = $value;
$this->types .= $type;
}
public function get(){
return array_merge(array($this->types), $this->values);
}
}
and this is my code for generating sql:
if(!empty($dataIni)){
$qArray[] = "BETWEEN V.DATA_EMISSAO ?";
$bindParam->add('s', $dataIni);
}
if(!empty($dataFim)){
$qArray[] = "?";
$bindParam->add('s', $dataFim);
}
$queryNFe .= implode(' AND ', $qArray);
$param = $bindParam->get();
$sqlNFe = $mysqli->prepare($queryNFe);
call_user_func_array(array($sqlNFe, 'bind_param'), $param);
$sqlNFe->execute();
The query clause is mounting right, the error is in call_user_func_array ()
Warning: call_user_func_array () expects parameter 1 to be a valid callback, first array member is not a valid class name or object in
I know it's in the first parameter but I can not see what's wrong
I've changed the code:
if(!empty($dataIni)){
$qArray[] = "V.DATA_EMISSAO BETWEEN ?";
$bindParam->add('s', $dataIni);
}
if(!empty($dataFim)){
$qArray[] = "?";
$bindParam->add('s', $dataFim);
}
$queryNFe .= implode(' AND ', $qArray);
$param = $bindParam->get();
$sqlNFe = $mysqli->prepare($queryNFe) or die($mysqli->error);
call_user_func_array(array($sqlNFe, 'bind_param'), $bindParam->get());
//$sqlNFe->bind_param('ss', $dataIni, $dataFim);
$sqlNFe->execute();
But now the error is this:
Warning: Parameter 2 to mysqli_stmt :: bind_param () expected to be a reference, value given in