-1
I started my studies recently and a question arose regarding the access of information of a method. I have an X.php file that has the following structure:
public function selectDB($sql,$params=null,$class=null){
$query=$this->connect()->prepare($sql);
$query->execute($params);
$total_q = $query->rowCount();
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));
}
self::__destruct();
return $rs;
}
And I have a Y.php page that makes use of this function. How do I make so that on the Y.php page the value of the variable is displayed $total_q
?
Could someone give me a light please?
In case I call you with a include. The problem, is that when I order to echo the variable, it shows nothing. But if I am in X.php and do echo, the result appears normally.
– user3142095
Sorry about the glitch, I didn’t notice something. The variable $total_q is inside a function or it is in local scope, (only exists inside the function). Put $total_q as return of the selectDB function as well, recommend using an array
– Guilherme Arantes
William, thank you very much. I declared it as a global variable, and it worked. Thank you very much. Abs,
– user3142095