Ola @Thiavo eu rodei o comando php -m e consta na minha máquina que o PDO está sim habilitado. mas mesmo assim ele não consegue encontrar o driver.
Como minhas pastas estão organizadas:
Segue a minhas classes:
ConnectionCreator.php
<?php
namespace Alura\Pdo\Domain\Infrastructure\Persistence;
use PDO;
class ConnectionCreator
{
public static function createConnection(): PDO
{
$databasePath = __DIR__ . '/../../../database.sqlite';
return new PDO('sqlite:' . $databasePath);
}
}
listar-alunos.php
<?php
require_once "vendor/autoload.php";
use Alura\Pdo\Domain\Infrastructure\Persistence\ConnectionCreator;
use Alura\Pdo\Domain\Model\Student;
$pdo = ConnectionCreator::createConnection();
$statment = $pdo->query('SELECT * FROM students');
$studentDataList = $statment->fetchAll(PDO::FETCH_ASSOC);
$studentList = [];
foreach($studentDataList as $studentData) {
$studentList[] = new Student(
$studentData['id'],
$studentData['name'],
new DateTimeImmutable($studentData['birth_date'])
);
}
echo "<pre>";
print_r($studentList);
echo "</pre>";
saída do terminal do comando php -m
prime@Inspiron5480f0f68e2e:~/projetos/pdo$ php -m
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20210902/pdo_sqlite (/usr/lib/php/20210902/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20210902/pdo_sqlite.so (/usr/lib/php/20210902/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[PHP Modules]
calendar
Core
ctype
date
dom
exif
FFI
fileinfo
filter
ftp
gettext
hash
iconv
igbinary
imap
json
libxml
mbstring
openssl
pcntl
pcre
PDO
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zlib
[Zend Modules]
Zend OPcache