Hello everyone, I used PDO directly in a model Cakephp 3.6 to make a request a little complex and for reasons of performance, after that my Models lose the connection to my database, $this->getConnection()
in my model return null, how can I reconnect my Models automatically?
How do you mean “used PDO directly in a model”?
Like you actually added another PDO connection manually in a model?
A very simplified example in model:
public function getPets() // params would be used in real app
{
$dbh = ConnectionManager::get('default');
$sql = "SELECT * FROM dc_pets Where `adopted` = :adpt";
$sth = $dbh->prepare($sql);
$params = ['adpt' => 0];
$sth->execute($params);
return $sth->fetchAll(\PDO::FETCH_OBJ);
}
Of course if for real I’d pass in an offset and a rows per page to paginate