PHP PDO could not find driver - php

I need to use PHP PDO to connect to a MariaDB database to do work. But when I run the php file through the processor it throws an error:
Fatal error: Uncaught PDOException: could not find driver in C:\Users
\...\Documents\Visual Studio 2017\Projects\...\...
\dashboard.php:16
Stack trace:
#0 C:\Users\...\Documents\Visual Studio 2017\Projects\...
\...\dashboard.php(16): PDO->__construct('mysql:host=;dbn...',
NULL, NULL, Array)
#1 {main}
thrown in C:\Users\...\Documents\Visual Studio 2017\Projects
\...\...\dashboard.php on line 16
I have the PDO drivers enabled in php.ini
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_pdo_obdc.dll

Found the problem, when I ran phpinfo() inside the php file I found:
Loaded Configuration File => (none)
Turns out the process that was executing the file was ignoring the php.ini file.

Related

connecting php to oracle 19c db

Trying to connect to oracle 19c from php the server is not on the same machine as the php, I have so far installed instant client 19_15, added it as a environment variable, and then in the php.ini file I have taken off the semi colon for both the files extension=oci8_19 and extension=pdo_oci not sure what else to do to make the php to connect to the oracle db.
some error messages I have been getting are: PDO: connection failed: could not find driver
and from oci_connect: Fatal error: Uncaught Error: Call to undefined function oci_connect() in Stack trace: #0 {main} thrown in on line 7
p.s. architecture is x64, php version is 8.1.8 and using apache24 lounge

php sqlite driver missing?

I am trying to connect to an existing database I created via DB browser for SQLite. It is saved as a file on my computer.
When using getAvailableDrivers, I am getting both MySQL and SQLite.
In phpinfo() I have the following entries:
PDO
PDO drivers -> MySQL, SQLite
pdo_sqlite
SQLite library -> 3.8.10.2
SQLite3
SQLite3 module version -> 0.7-dev
SQLite Library 3.9.10.2
SQLite3 extension dir -> c:\xampp\SQLite
I have written the following code to just establish connection:
<?php
phpinfo();
print_r(PDO::getAvailableDrivers());
$handler = new PDO('SQLite3:host=127.0.0.1;dbname=test', '', '');
?>
But when I try it I get the following error message:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\xampp\htdocs\Ebsco\Users.php:4 Stack trace: #0 C:\xampp\htdocs\Ebsco\Users.php(4): PDO->__construct('SQLite3:host=12...', '', '') #1 {main} thrown in C:\xampp\htdocs\Ebsco\Users.php on line 4
I have searched several places online and several answers on Stack Overflow, but they did not help with a solution.
Any idea what could be causing this?
I noticed that the dir in the error message is not the same directory which I specified in the php.ini (which is also returned by phpinfo();), but I'm not sure if that is the cause, and if so what is causing it to search for the driver in that location.

PDO : Uncaught PDOException: could not find driver

I'm using odbc and XAMPP. I'm receiving the fatal error of could not find driver
Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\index.php:5 Stack trace: #0 C:\xampp\htdocs\index.php(5): PDO->__construct('odbc:BEGIN') #1 {main} thrown in C:\xampp\htdocs\index.php on line 5
This is the code the error refering to :
$conn = new PDO ("odbc:BEGIN");
Is there any module that I should add to the php.ini like this answer or there are other solution?
You need to enable those extensions in order to have ODBC PDO driver working
php_pdo.dll
php_odbc.dll
php_pdo_odbc.dll
After enabling those extension as #Sarhan said, we need to restart Apache in order for it to work.

error with PDO connection in php

i have PHP Version 5.2.8 on my windows 2003 server, i am trying to connect with database
$dbh = new PDO("mysql:host=localhost;port=3306;dbname=$db_name", $db_user, $db_pass);
but when i use this statement i got following error
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
in bin\db.php:14 Stack trace: #0 bin\db.php(14):
PDO->__construct('mysql:host=loca...', 'root', '123') #1
main.php(4): include_once('C:\Inetpub\wwwr...') #2
{main} thrown in bin\db.php on line 14
how can i fix this problem?
Thanks
You must remove the ; on this line in php.ini :
;extension=php_pdo_mysql.dll
extension=php_pdo_mysql.dll
If you're upgrading PHP, be sure to check your environment variable information, especially your `PATH, and reboot if you change it.
I was using a php.ini file from a different directory. As Sebastian Grignoli suggests, check your phpinfo() results for the location of the php.ini it's using.

Couldn't locate driver named mysql in doctrine php

My application was working perfectly on localhost. But when i uploaded the application on server i got an error. I made a test file to check databse connection, this is the error i am getting. Please hellp me how to fix this..
Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'Couldn't locate driver named mysql' in /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/lib/Doctrine/Connection.php:492 Stack trace: #0 /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/lib/Doctrine/Connection/Mysql.php(101): Doctrine_Connection->connect() #1 /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/lib/Doctrine/Connection.php(1008): Doctrine_Connection_Mysql->connect() #2 /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/lib/Doctrine/Query/Abstract.php(1094): Doctrine_Connection->execute('SELECT u.id AS ...', Array) #3 /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/lib/Doctrine/Query/Abstract.php(1142): Doctrine_Query_Abstract->_execute(Array) #4 /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/models/Users.php(22): Doctrine_Query_Abstract->execute() #5 /hermes/web05/b1392/moo.fanyer/httpdocs/test.php(8): Users->get_details_username('mohit') #6 {main} thrown in /hermes/web05/b1392/moo.fanyer/httpdocs/doctrine/lib/Doctrine/Connection.php on line 492
Edit: how to enable my sql drivers..???
apt-get install php5-mysql ---------------
Enable pdo_mysql in the php.ini file
Make sure that:
mysql extension is enabled on the server where you have uploaded files.
you have specified the correct paths.
there are no directory permission issues

Categories