PDO : Uncaught PDOException: could not find driver - php

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.

Related

Can't connect to odbc in php. could not find drivers

im trying to connect to a database on odbc with php and i get the error of
Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\testarsybase\index.php:3 Stack trace: #0 C:\xampp\htdocs\testarsybase\index.php(3): PDO->__construct('odbc:host=192.1...', 'sa', '') #1 {main} thrown in C:\xampp\htdocs\testarsybase\index.php on line 3
im using the PDO('odbc (..)') to connect
What should i do?
See if this situation helps you. It seems to be the same question.
PDO returning error “could not find driver” with a known working DSN

PHP PDO could not find driver

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.

I got some error in this code for two file. One is workshop_connect.php and another is workshop_retrieve.php

$con = mysql_connect('HOSTNAME', 'USER', 'PASSWORD');
I run with the above code and it shows the error below
Fatal error: Uncaught Error: Call to undefined function
mysql_connect() in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_connect.php:3
Stack trace: #0 {main} thrown in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_connect.php on
line 3
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_retrieve.php:3
Stack trace: #0 {main} thrown in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_retrieve.php on
line 3
If you are use PHP 7+ MYSQL no longer exist, try MYSQLi
if you are using any 5.x version, follow below
Try checking if the PHP MySQL extension is enabled or not.
<?php
phpinfo();
?>
if you cannot find mysql extension there, theme mysql extension is not enabled.
Locate php.ini file, and edit it.
find the line
;extension=php_mysql.dll
and remove ; from the line
extension=php_mysql.dll

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.

PHP Connection to MS SQLServer 2008 from Linux via PDO

I need to connect to a MS SQLServer 2008 service from PHP on Ubuntu, and I would like to do so using PDO. I believe I have installed all the prerequisite libraries, and I am indeed able to connect using tsql on the command line and using mssql_connect() in code. I can't figure out what the proper DSN is, or if there are any additional PDO-specific configuration steps I am missing.
I am using the following DSN (where $db* variables are populated with their appropriate values):
odbc:Driver=FreeTDS;SERVER=$dbServer;DATABASE=$dbSchema;UID=$dbUser;PWD=$dbPasswd"
My error message is:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /home/timothy/test.php:4
Stack trace:
#0 /home/timothy/test.php(4): PDO->__construct('odbc:Driver=Fre...')
#1 {main}
thrown in /home/timothy/test.php on line 4
What additional configuration steps have I over looked?
Thanks in advance.
You shouldn't need any additional configuration if you can connect with tsql and the mssql extension. You probably just don't have the correct dsn. This documentation should help. Try new PDO("dblib:host=xx.xx.xx.xx;dbname=mydatabase", "username", "password");

Categories