Warning: mysqli::construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in C:\xampp\htdocs\blog\config.php on line 7 conectado Fatal error: Uncaught ArgumentCountError: Too few arguments to function Artigo::construct(), 0 passed in C:\xampp\htdocs\blog\index.php on line 6 and exactly 1 expected in C:\xampp\htdocs\blog\Artigo.php:7 Stack trace: #0 C:\xampp\htdocs\blog\index.php(6): Artigo->__construct() #1 {main} thrown in C:\xampp\htdocs\blog\Artigo.php on line 7
<?php
require 'config.php';
include 'Artigo.php';
$artigo = new Artigo();
$artigos = $artigo-> exibirTodos();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Meu Blog</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
<h1>Meu Blog</h1>
<?php foreach ($artigos as $artigo) : ?>
<h2>
<a href="<?php echo $artigo['link']; ?>">
<?php echo $artigo['titulo']; ?>
</a>
</h2>
<p>
<?php echo $artigo['conteudo']; ?>
</p>
<?php endforeach; ?>
</div>
</body>
</html>
<?php
Class Artigo
{
private $mysql;
public function __construct(mysqli $mysql){
$this-> mysql = $mysql;
}
public function exibirTodos(): array
{
$resultado = $this->mysql->query('SELECT id,titulo,conteudo FROM artigos');
$artigos = $resultado->fetch_all(mysqli_assoc);
return $artigos;
}
}