-3
Hello, I have an appointment function at the bank. If the query returns 1 or more rows, the function returns an object (or a class), but if the query does not return any rows, the return is:
Array
(
[0] => 00000
[1] =>
[2] =>
)
The function that makes the query:
public function selectDB($sql,$params=null,$class=null){
$query=$this->connect()->prepare($sql);
$query->execute($params);
if(isset($class)){
$rs = $query->fetchAll(PDO::FETCH_CLASS,$class) or die(print_r($query->errorInfo(), true));
}else{
$rs = $query->fetchAll(PDO::FETCH_OBJ) or die(print_r($query->errorInfo(), true));
}
return $rs;
}
I would like some suggestion to make this function return only 0 if the query has no lines. Thanks in advance.
And your connection? How are you?
– Diego Ananias
private function connect(){
 try
 {
 $this->conexao = new PDO($this->getDBType().":host=".$this->getHost().";port=".$this->getPort().";dbname=".$this->getDB(), $this->getUser(), $this->getPassword());
 }
 catch (PDOException $i)
 {
 //se houver exceção, exibe
 die("Erro: <code>" . $i->getMessage() . "</code>");
 }
 
 return ($this->conexao);
 }
– Gabriel Sarates