Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

PDO : Uncaught PDO exception: could not find driver #65

Open
StephenKirwin opened this issue Jun 29, 2020 · 2 comments
Open

PDO : Uncaught PDO exception: could not find driver #65

StephenKirwin opened this issue Jun 29, 2020 · 2 comments

Comments

@StephenKirwin
Copy link

StephenKirwin commented Jun 29, 2020

I used this layer to create a PHP lambda API. I then tried to create a PDO and connect it to a MySQL database. I got the following error
"Uncaught PDOException: could not find driver in /var/task/index.php"

My php.ini file contains the following:
extension=json.so
extension=mysql.so
extension=pdo_mysql.so
extension=pdo.so
extension=php_pdo_mysql.dll
extension=pdo_mysql.dll

Here is my index.php code for creating the DB
$conn = null;

$conn = new PDO('mysql:host=' . $host . ';dbname=' . $db_name, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

@czerniachowicz
Copy link

I'm seeing the same or similar, its not that it can't find the extension but it doesn't seem to be compiled properly:

undefined symbol: mysqlnd_allocator

[Sun Aug 30 20:24:07 2020] PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: /opt/lib/php/7.3/modules/pdo_mysql.so (/opt/lib/php/7.3/modules/pdo_mysql.so: undefined symbol: mysqlnd_allocator), /opt/lib/php/7.3/modules/pdo_mysql.so.so (/opt/lib/php/7.3/modules/pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 |  

Any thoughts?

@czerniachowicz
Copy link

The solution is quite simple actually, in your php.ini reorder your extensions so that the mysqlnd is loaded first, and any mysql related extensions are last.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants