Erro apontado: PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such table: Students in C:\Users\walla\OneDrive\Área de Trabalho\PHP\php-pdo-projeto-inicial\lista-alunos.php:8 Stack trace: #0 C:\Users\walla\OneDrive\Área de Trabalho\PHP\php-pdo-projeto-inicial\lista-alunos.php(8): PDO->query('SELECT * FROM S...') #1 {main} thrown in C:\Users\walla\OneDrive\Área de Trabalho\PHP\php-pdo-projeto-inicial\lista-alunos.php on line 8
projeto-inicial.php
<?php
use Alura\Pdo\Domain\Model\Student;
require_once 'vendor/autoload.php';
$student = new Student(
null,
'Wallace Henrique',
new \DateTimeImmutable('2007-11-11')
);
echo $student->age();
conexao.php
<?php
use Alura\Pdo\Domain\Model\Student;
$sqlitePath = __DIR__ . 'banco.sqlite';
$pdo = new PDO("sqlite:$sqlitePath");
$pdo->exec('CREATE TABLE Students(id INTEGER PRIMARY KEY, name TEXT, birthDate TEXT);');
echo 'Conectado';
inserir-alunos.php
<?php
use Alura\Pdo\Domain\Model\Student;
require_once './vendor/autoload.php';
$sqlitePath = __DIR__ . 'banco.sqlite';
$pdo = new PDO("sqlite:$sqlitePath");
$student = new Student(null, 'Wallace Henrique', new \DateTimeImmutable('2007-11-11'));
$sqlInsert = "INSERT INTO Students (name, birthDate) VALUES ('{$student->name()}', '{$student->birthDate()->format('Y-m-d')}');
";
var_dump($pdo->exec($sqlInsert));
lista-alunos.php
<?php
require_once 'vendor/autoload.php';
$databasePath = __DIR__ . '/banco.sqlite';
$pdo = new PDO(dsn: 'sqlite:' . $databasePath);
$statement = $pdo->query('SELECT * FROM Students;');
var_dump($statement->fetchAll());
Não sei se era para aparecer alguma coisa no arquivo .sqlite mas lá está vazio