Здраствуйте, не могу сделать SQL-запрос. Мне нужно выбрать столбец film_name из базы данных. Но произошла ошибка - Fatal error: Uncaught Error: Call to a member function query() on null in C:\OSPanel\domains\localhost\index.php:23 Stack trace: #0 {main} thrown in C:\OSPanel\domains\localhost\index.php on line 23
index.php
<?php
require_once 'includes/config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?php echo $config['title']; ?></title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/media.css">
<link href="https://fonts.googleapis.com/css?family=Revalia" rel="stylesheet">
</head>
<body>
<?php require_once "includes/header.php"; ?>
<section>
<div class="container">
<?php
$stmt = $pdo->query('SELECT film_name FROM new_film');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['film_name'];
};
?>
</div>
</section>
<script src="js/scripts.js"></script>
</body>
</html>
connection.php
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'main';
try {
$dsn = "mysql:host = $host; dbname = $dbname";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $username, $password, $opt);
}
catch (PDOException $e) {
die('Not connect: ' . $e->getMessage());
}
$pdo = null;
?>
Продвижение своими сайтами как стратегия роста и независимости