6
respostas

Erro ai tenta conexão com MySQL

Ao rodar o arquivo de conexão surge esse erro:

PHP Fatal error: Uncaught PDOException: could not find driver in /home/aurelio/Aurelio Docs/Programação/PHP/Programas/PHP e MySQL/projeto-inicial/src/conexao.php:3 Stack trace: #0 /home/aurelio/Aurelio Docs/Programação/PHP/Programas/PHP e MySQL/projeto-inicial/src/conexao.php(3): PDO->__construct() #1 {main} thrown in /home/aurelio/Aurelio Docs/Programação/PHP/Programas/PHP e MySQL/projeto-inicial/src/conexao.php on line 3

Utilizo o Ubuntu.

6 respostas

Eu já retirei o ; que tem antes do extension=pdo_mysql, porém o erro vira esse:

PHP Warning: Failed loading Zend extension 'opcache.so' (tried: ext/opcache.so (ext/opcache.so: cannot open shared object file: No such file or directory), ext/opcache.so.so (ext/opcache.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: ext/pdo_mysql (ext/pdo_mysql: cannot open shared object file: No such file or directory), ext/pdo_mysql.so (ext/pdo_mysql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo.so' (tried: ext/pdo.so (ext/pdo.so: cannot open shared object file: No such file or directory), ext/pdo.so.so (ext/pdo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'calendar.so' (tried: ext/calendar.so (ext/calendar.so: cannot open shared object file: No such file or directory), ext/calendar.so.so (ext/calendar.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'ctype.so' (tried: ext/ctype.so (ext/ctype.so: cannot open shared object file: No such file or directory), ext/ctype.so.so (ext/ctype.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'exif.so' (tried: ext/exif.so (ext/exif.so: cannot open shared object file: No such file or directory), ext/exif.so.so (ext/exif.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'ffi.so' (tried: ext/ffi.so (ext/ffi.so: cannot open shared object file: No such file or directory), ext/ffi.so.so (ext/ffi.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'fileinfo.so' (tried: ext/fileinfo.so (ext/fileinfo.so: cannot open shared object file: No such file or directory), ext/fileinfo.so.so (ext/fileinfo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'ftp.so' (tried: ext/ftp.so (ext/ftp.so: cannot open shared object file: No such file or directory), ext/ftp.so.so (ext/ftp.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'gettext.so' (tried: ext/gettext.so (ext/gettext.so: cannot open shared object file: No such file or directory), ext/gettext.so.so (ext/gettext.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'iconv.so' (tried: ext/iconv.so (ext/iconv.so: cannot open shared object file: No such file or directory), ext/iconv.so.so (ext/iconv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite.so' (tried: ext/pdo_sqlite.so (ext/pdo_sqlite.so: cannot open shared object file: No such file or directory), ext/pdo_sqlite.so.so (ext/pdo_sqlite.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'phar.so' (tried: ext/phar.so (ext/phar.so: cannot open shared object file: No such file or directory), ext/phar.so.so (ext/phar.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'posix.so' (tried: ext/posix.so (ext/posix.so: cannot open shared object file: No such file or directory), ext/posix.so.so (ext/posix.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'readline.so' (tried: ext/readline.so (ext/readline.so: cannot open shared object file: No such file or directory), ext/readline.so.so (ext/readline.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'shmop.so' (tried: ext/shmop.so (ext/shmop.so: cannot open shared object file: No such file or directory), ext/shmop.so.so (ext/shmop.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'sockets.so' (tried: ext/sockets.so (ext/sockets.so: cannot open shared object file: No such file or directory), ext/sockets.so.so (ext/sockets.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Olá, Aurélio! Como vai?

A mensagem de erro "could not find driver" indica que o PHP não conseguiu encontrar o driver PDO necessário para se conectar ao MySQL.

No Ubuntu, você pode instalar o driver PDO para MySQL com o seguinte comando no terminal:

sudo apt-get install php-mysql

Depois de instalar o driver, você precisará reiniciar o servidor Apache para que as alterações tenham efeito. Você pode fazer isso com o seguinte comando:

sudo service apache2 restart

E lembre-se, sempre que modificar algo relacionado ao PHP ou ao servidor Apache, é necessário reiniciar o servidor para que as alterações entrem em vigor.

Espero ter ajudado e bons estudos!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓.

Outro erro aparece

PHP Warning: Failed loading Zend extension 'opcache.so' (tried: ext/opcache.so (ext/opcache.so: cannot open shared object file: No such file or directory), ext/opcache.so.so (ext/opcache.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: ext/pdo_mysql (ext/pdo_mysql: cannot open shared object file: No such file or directory), ext/pdo_mysql.so (ext/pdo_mysql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'mysqlnd.so' (tried: ext/mysqlnd.so (ext/mysqlnd.so: cannot open shared object file: No such file or directory), ext/mysqlnd.so.so (ext/mysqlnd.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo.so' (tried: ext/pdo.so (ext/pdo.so: cannot open shared object file: No such file or directory), ext/pdo.so.so (ext/pdo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'calendar.so' (tried: ext/calendar.so (ext/calendar.so: cannot open shared object file: No such file or directory), ext/calendar.so.so (ext/calendar.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'ctype.so' (tried: ext/ctype.so (ext/ctype.so: cannot open shared object file: No such file or directory), ext/ctype.so.so (ext/ctype.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'exif.so' (tried: ext/exif.so (ext/exif.so: cannot open shared object file: No such file or directory), ext/exif.so.so (ext/exif.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'ffi.so' (tried: ext/ffi.so (ext/ffi.so: cannot open shared object file: No such file or directory), ext/ffi.so.so (ext/ffi.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'fileinfo.so' (tried: ext/fileinfo.so (ext/fileinfo.so: cannot open shared object file: No such file or directory), ext/fileinfo.so.so (ext/fileinfo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'ftp.so' (tried: ext/ftp.so (ext/ftp.so: cannot open shared object file: No such file or directory), ext/ftp.so.so (ext/ftp.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'gettext.so' (tried: ext/gettext.so (ext/gettext.so: cannot open shared object file: No such file or directory), ext/gettext.so.so (ext/gettext.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: ext/pdo_mysql.so (ext/pdo_mysql.so: cannot open shared object file: No such file or directory), ext/pdo_mysql.so.so (ext/pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite.so' (tried: ext/pdo_sqlite.so (ext/pdo_sqlite.so: cannot open shared object file: No such file or directory), ext/pdo_sqlite.so.so (ext/pdo_sqlite.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'phar.so' (tried: ext/phar.so (ext/phar.so: cannot open shared object file: No such file or directory), ext/phar.so.so (ext/phar.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'posix.so' (tried: ext/posix.so (ext/posix.so: cannot open shared object file: No such file or directory), ext/posix.so.so (ext/posix.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'readline.so' (tried: ext/readline.so (ext/readline.so: cannot open shared object file: No such file or directory), ext/readline.so.so (ext/readline.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'shmop.so' (tried: ext/shmop.so (ext/shmop.so: cannot open shared object file: No such file or directory), ext/shmop.so.so (ext/shmop.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'sockets.so' (tried: ext/sockets.so (ext/sockets.so: cannot open shared object file: No such file or directory), ext/sockets.so.so (ext/sockets.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'sqlite3.so' (tried: ext/sqlite3.so (ext/sqlite3.so: cannot open shared object file: No such file or directory), ext/sqlite3.so.so (ext/sqlite3.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'sysvmsg.so' (tried: ext/sysvmsg.so (ext/sysvmsg.so: cannot open shared object file: No such file or directory), ext/sysvmsg.so.so (ext/sysvmsg.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'sysvsem.so' (tried: ext/sysvsem.so (ext/sysvsem.so: cannot open shared object file: No such file or directory), ext/sysvsem.so.so (ext/sysvsem.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'sysvshm.so' (tried: ext/sysvshm.so (ext/sysvshm.so: cannot open shared object file: No such file or directory), ext/sysvshm.so.so (ext/sysvshm.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'tokenizer.so' (tried: ext/tokenizer.so (ext/tokenizer.so: cannot open shared object file: No such file or directory), ext/tokenizer.so.so (ext/tokenizer.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Fatal error: Uncaught Error: Class "PDO" not found in /opt/lampp/htdocs/Programas/projeto-inicial/src/conexao.php:3 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/Programas/projeto-inicial/src/conexao.php on line 3

Bom dia, Aurélio! Peço desculpa pela demora em retornar.

Esse seu caso está um pouco estranho, não era para esses tipos de erros estarem acontecendo, mas tudo bem, vamos tentar resolver isso!

Precisarei de mais informações para poder ajudá-lo, então peço que compartilhe comigo todos os passos e comandos que você realizou para a instalação do PHP e como exatamente você está testando para que esse erro seja apresentado.

Fico no aguardo e à disposição

Bom dia, eu desinstalei tudo e instalei novamente, sanando assim o erro. Grato