Есть код (на месте # у меня стоят правильные имена, проблема не из-за этого):
<?php
function connectDB() {
try {
$pdo = new PDO('mysql:host=localhost;dbname=#', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
exit($e->getMessage());
}
}
function closeDB() {
$pdo = null;
}
function getA() {
connectDB();
$select = $pdo->query("SELECT * FROM # ORDER BY id DESC", PDO::FETCH_ASSOC);
$result = $select->fetchAll();
var_dump($result);
closeDB();
}
getA();
?>
Выдает ошибку:
Fatal error: Uncaught Error: Call to a member function query() on null in /storage/emulated/legacy/htdocs/functions/functions.php:18 Stack trace: #0 /storage/emulated/legacy/htdocs/functions/functions.php(47): getA() #1 {main} thrown in /storage/emulated/legacy/htdocs/functions/functions.php on line 18