PHP: Unable to load dynamic library ‘pdo_mysql’ and Uncaught PDOException: could not find driver

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>OS: Linux Mint 21.3 Cinnamon
PHP Version: 8.3
</code>
<code>OS: Linux Mint 21.3 Cinnamon PHP Version: 8.3 </code>
OS: Linux Mint 21.3 Cinnamon
PHP Version: 8.3

I’m learning PHP and have installed it using the PPA ppa:ondrej/php. I’m trying to connect to a MySQL database that’s running inside a Docker container.

The Docker file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FROM mysql
ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_USER=user
ENV MYSQL_PASSWORD=pass
ENV MYSQL_DATABASE=blog
COPY init.sql /docker-entrypoint-initdb.d/
EXPOSE 3306
</code>
<code>FROM mysql ENV MYSQL_ROOT_PASSWORD=root ENV MYSQL_USER=user ENV MYSQL_PASSWORD=pass ENV MYSQL_DATABASE=blog COPY init.sql /docker-entrypoint-initdb.d/ EXPOSE 3306 </code>
FROM mysql

ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_USER=user
ENV MYSQL_PASSWORD=pass
ENV MYSQL_DATABASE=blog

COPY init.sql /docker-entrypoint-initdb.d/

EXPOSE 3306

The container is up and running as I am able to connect with it using python as well run SQL queries by going into the docker container.

When I run the PHP built in server using php -S localhost:8080, I get the following error log

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[Thu Sep 26 11:14:47 2024] PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0
[Thu Sep 26 11:14:47 2024] PHP 8.3.11 Development Server (http://localhost:8080) started
[Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 Accepted
[Thu Sep 26 11:14:52 2024] PHP Fatal error: Uncaught PDOException: could not find driver in /home/anon/Desktop/php/index.php:5
Stack trace:
#0 /home/anon/Desktop/php/index.php(5): PDO->__construct()
#1 {main}
thrown in /home/anon/Desktop/php/index.php on line 5
[Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 [500]: GET / - Uncaught PDOException: could not find driver in /home/anon/Desktop/php/index.php:5
Stack trace:
#0 /home/anon/Desktop/php/index.php(5): PDO->__construct()
#1 {main}
thrown in /home/anon/Desktop/php/index.php on line 5
[Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 Closing
</code>
<code>[Thu Sep 26 11:14:47 2024] PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0 [Thu Sep 26 11:14:47 2024] PHP 8.3.11 Development Server (http://localhost:8080) started [Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 Accepted [Thu Sep 26 11:14:52 2024] PHP Fatal error: Uncaught PDOException: could not find driver in /home/anon/Desktop/php/index.php:5 Stack trace: #0 /home/anon/Desktop/php/index.php(5): PDO->__construct() #1 {main} thrown in /home/anon/Desktop/php/index.php on line 5 [Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 [500]: GET / - Uncaught PDOException: could not find driver in /home/anon/Desktop/php/index.php:5 Stack trace: #0 /home/anon/Desktop/php/index.php(5): PDO->__construct() #1 {main} thrown in /home/anon/Desktop/php/index.php on line 5 [Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 Closing </code>
[Thu Sep 26 11:14:47 2024] PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0
[Thu Sep 26 11:14:47 2024] PHP 8.3.11 Development Server (http://localhost:8080) started
[Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 Accepted
[Thu Sep 26 11:14:52 2024] PHP Fatal error:  Uncaught PDOException: could not find driver in /home/anon/Desktop/php/index.php:5
Stack trace:
#0 /home/anon/Desktop/php/index.php(5): PDO->__construct()
#1 {main}
  thrown in /home/anon/Desktop/php/index.php on line 5
[Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 [500]: GET / - Uncaught PDOException: could not find driver in /home/anon/Desktop/php/index.php:5
Stack trace:
#0 /home/anon/Desktop/php/index.php(5): PDO->__construct()
#1 {main}
  thrown in /home/anon/Desktop/php/index.php on line 5
[Thu Sep 26 11:14:52 2024] 127.0.0.1:38112 Closing

the index.php:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
require("utils/functions.php");
// require("router.php");
$dsn = "mysql:host=localhost;port=3306;dbname=blog;charset=utf8mb4";
$pdo = new PDO($dsn, "user", "pass");
$statement = $pdo->prepare("SELECT * FROM posts");
$statement->execute();
$posts = $statement->fetchAll();
dd($posts)
?>
</code>
<code><?php require("utils/functions.php"); // require("router.php"); $dsn = "mysql:host=localhost;port=3306;dbname=blog;charset=utf8mb4"; $pdo = new PDO($dsn, "user", "pass"); $statement = $pdo->prepare("SELECT * FROM posts"); $statement->execute(); $posts = $statement->fetchAll(); dd($posts) ?> </code>
<?php
    require("utils/functions.php");
    // require("router.php");
    $dsn = "mysql:host=localhost;port=3306;dbname=blog;charset=utf8mb4";
    $pdo = new PDO($dsn, "user", "pass");
    $statement = $pdo->prepare("SELECT * FROM posts");
    $statement->execute();
    $posts = $statement->fetchAll();
    dd($posts)
?>

the functions.php contains the function dd:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
function dd($supGlo) {
echo "<pre>";
var_dump($supGlo);
echo "</pre>";
die();
}
?>
</code>
<code><?php function dd($supGlo) { echo "<pre>"; var_dump($supGlo); echo "</pre>"; die(); } ?> </code>
<?php
function dd($supGlo) {
    echo "<pre>";
    var_dump($supGlo);
    echo "</pre>";
    die();
}
?>

I done the following to solve the issue without any success:

  • Remove php-common and reinstalled PHP
  • Installed php-mysql
  • Installed php8.3-mysqlnd
  • Installed php8.3-pdo-mysql
  • Installed php8.3-mysql
  • Uncommented in extension=pdo_mysql in php.ini in both the cli and apache2 directories
  • restarted the apache2 service
  • Have confirmed that I only have one PHP version installed
  • Used phpenmod to enable pdo_mysql and restarted the apache2

When I run php --ri pdo, I get the below output,

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0
PDO
PDO support => enabled
PDO drivers => mysql
</code>
<code>PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0 PDO PDO support => enabled PDO drivers => mysql </code>
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0

PDO

PDO support => enabled
PDO drivers => mysql

If I comment the extension=pdo_mysql line in php.ini then the warning, is removed.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0'
</code>
<code>PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0' </code>
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql (tried: /usr/lib/php/20230831/pdo_mysql (/usr/lib/php/20230831/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/pdo_mysql.so (/usr/lib/php/20230831/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0'

But the PDO drivers are still missing. Also I have confirmed that the /usr/lib/php/20230831/ directory exists and the shared object pdo_mysql.so also exists in it.

New contributor

pippen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

4

I solved the above issue,

  • Firstly, make sure that you have only one version of PHP installed and that you have installed the php-mysql extension from your package manager.
  • Then inside your /etc/php/cli and /etc/php/apache2 directories, edit your php.ini, search for the extension_dir and set it to your extension directory.
  • To find your extension directory, go to /lib/php/******* the ******** represents YYYYMMDD and can be different for you but will always be in that format, i.e., mine was /lib/php/20230831. This is your extension directory
  • Also, if you’re using a docker container, make sure that your PDO host is 127.0.0.1 and not localhost
New contributor

pippen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật