PHP Problem with PDO: could not find driver - php

Hello i am trying to build a webapp using oracle DB.
So I created connect.php using PDO to access the Oracle database. But i get the message: could not find driver
So i am using apache2 and in my php.ini this extensions are activated:
extension=oci8_12c ; Use with Oracle Database 12c Instant Client
extension=oci8_19 ; Use with Oracle Database 19 Instant Client
extension=odbc
extension=pdo_firebird
extension=pdo_mysql
extension=pdo_oci
extension=pdo_odbc
Maybe i am missing some packages or extensions? Can u help me out? I my phpinfo i cant find an extra section for oci and i guess thats bad?
I am working on Ubuntuu VM but my database is on another server. I have Installed PHP 8.1.2
please help me to eliminate this php error

Just run
sudo apt install php-mysql
in terminal
Hi I have also faced this issue but this article helped me you no need to edit .ini file just follow this article
PDOException: could not find driver

Related

PHP: pdo_oci driver does not work under apache, but does work from console

I'm having a very puzzling situation with PHP PDO and Oracle. I'm
running on Centos 7. My script, under Apache gets the error
"ERROR:could not find driver", however the script runs fine from the command line.
From the command line when I run a test script to list the drivers:
foreach(PDO::getAvailableDrivers() as $driver)
echo $driver, '', "\n";
it returns:
mysql oci pgsql sqlite
but when run under apache, oci is missing:
mysql pgsql sqlite
To add to this mystery, running phpinfo() shows in the section
"Additional .ini files parsed" an entry for /etc/php.d/pdo_oci.ini (for both console and apache).
Any ideas as to why the oci driver is not showing up when the script
is run under apache?
I "solved" this problem by punting on getting it to work using the Oracle installation configuration. I installed Instant Client and that got PHP to recognize the oci module both in command line and under apache (building pdo_oci with ./configure --with-pdo-oci=instantclient,/usr,11.2)
There were further issues with unrecognized TNS_ADMIN values. I worked around that by using the alternative PDO DSN spec for Oracle connections:
oci:dbname=//HOST[:PORT]/SERVICE_NAME
Thanks to anyone kind enough to have spent time on this. This experience, like many Oracle-related ones, reminds me why I use Postgres.

PHP PDO could'nt not find driver

I'm getting error of PDO cannot find driver using PDO in environment. I'm using xamp on a Mac.
I had got to know the problem and I've installed freetds using homebrew install, and had successfully connected to the azure mssql server using below command
tsql -H 234fddfg.database.windows.net -p 1433 -U dbuser -P db123!
but I don't know what to do next.
I've tried below php code but I'm still getting the same error.
$dbh = new PDO("sqlsrv:Server=localhost;Database=mydb", "dbuser", "db123");
Driver for Microsoft SQL Server for PHP is needed to be installed for this.
Follow this link:
https://www.microsoft.com/en-in/download/details.aspx?id=20098
Perform the following steps to download and install the Microsoft Drivers for PHP for SQL Server (example below for 3.2 version):
1. Download SQLSRV32.EXE to a temporary directory
2. Run SQLSRV32.EXE
3. When prompted, enter the path to the PHP extensions directory
4. After extracting the files, read the Installation section of the SQLSRV32_Readme.htm file for next steps
Now just add the following line to your PHP.ini (this is for the non-thread safe version of PHP, which you are most likely using when you have installed PHP to use IIS FastCGI, which we recommend):
extension=php_sqlsrv.dll
And Restart server
Have you installed PDO_DBLIB, it seems that in OSX, we need to leverage PDO_DBLIB as the pdo driver connecting to MS SQL, e.g.
$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname", "$dbuser","$dbpwd");
you can refer to Configure PHP environment on Mac to connect to SQL Server using PDO interface for more information.

Uncaught exception 'PDOException' with message 'could not find driver' (to an Oracle DB)

I've been encountering this error after installing Wamp, and have tried enabling all of the PDO's contained in php.ini (located in the Apache bin folder).
The error is:
PDOException: could not find driver in C:\wamp\www\common_db.php on line 27
Where line 27 is:
$db = new PDO("oci:dbname=".$oraDB, $dbusername, $dbuserpassword);
I have used phpinfo () to check which PDO's have been enabled. I've uploaded my php info onto Google Drive.
I'm trying to connect to an Oracle database, and have php_pdo_oci.dll unchecked in php.ini. However, this doesn't appear to have resolved the missing driver error.
Might anybody know what driver I could possibly be missing?
As well as enabling php_pdo_oci.dll in your PHP configuration, you also have to have an ORACLE driver installed on your system. The PHP extension is just an interface between your PHP code and the ORACLE driver, or Instant Client as it is called.
So depending on the Version of ORACLE you are using will depend the specific extension you activate and then the specific Instant Client that you also have to load onto the system running your Apache and PHP.
Also you have to activate the generic
;extension=php_oci.dll
And one of the specific version extensions.
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client

PHP Warning at startup while trying to load php_oci8.dll

I'm using XAMPP and trying to configure Oracle connection for sql.
I uncommented the line extension=php_oci8.dll and at first it ended up with an error (that oci.dll is missing), but later I downloaded instantclient from Oracle web pages. I tried with versions 10.2, 11.2, and 12.1 but neither worked. Obviously I've added the path to those libraries to my PATH env variable.
The warning I'm getting at the startup of Apache is: PHP Warning: PHP Startup: in Unknown on line 0
The error when I'm trying to connect is: PHP Fatal error: Call to undefined function oci_connect() in ...
I've tried with php_oci8.dll and php_oci8_11g.dll. Those files are in my php/ext directory (they were included in xampp), my instantclient is added to PATH and the warning doesn't show up if I disable those modules. I've tried restarting services and computer.
Can you help me find a solution how to configure it correctly? I'm using Windows 8.1 with administrative privileges.
BTW. My phpinfo() says that OCI8 is activated (but functions like oci_connect still don't work).
EDIT: When I tried running PHP manually I finally got the error to display what was wrong: Unable to load dynamic library 'C:\Program Files (x86)\PHP\ext\php_oci8_11g.dll' - %1 is not a valid Win32 application. in Unknown on line 0 Can you help me find out where can I download a correct version?
There was a problem with 64bit version of instantclient. If you ever have the same issue, please install 32bit version of instantclient.
To be honest the easiest way is just to follow PROPER instructions: http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-084410.html
I tried a lot of other advices and they all went really bad on me (not just because I used different bit version - also I copied the files everywhere following stupid advices and it was hard to correct it)
Its because your Oracle is 64 bit. Remove it and install a 32 bit version of Oracle client and it will work.
It looks like your extension are not install properly. Try to update it or reinstall it with pecl with
pecl install extname
You should also check extension_dir directive in php.ini and check if the PHP folder is added to the path
There's an alternate way to solve this: Install the full Oracle Client, not the basic zip, you can get it at oracle site (about 1Gb):
http://www.oracle.com/technetwork/database/enterprise-edition/downloads/oracle12c-windows-3633015.html
Im using Windows 10, Apache 2.4, PHP 7.1 (all x64) and it works. Also tryed PHP 5.6 and it works too. Still use the php_oci8_11g.dll from the basic client zip to match your php and system version.
You can search the site to find older client versions (11g, 32bits, etc) but Im working with de 12c client and accessing an Oracle 11g enterprise server.
I found a lot of occurrencies of this same error all around, but none gave me this solution. Hope taht helps.

PHP (WAMP) OCI8 driver setup problem

Greetings,
I need to install oci8 drivers for PHP, but I’m having some trouble.
I already have a WAMP install, which comes with the oci8 extension, and have done the following in effort to set it up:
Enabled the extension by adding the following to my php.ini file in my Apache docroot as a local variable:
[PHP_OCI8]
extension=php_oci8.dll
Added my extensions directory path to my PATH environment variable on windows (c:/wamp/bin/php/php5.3.0/ext/;)
Added the same extensions directory to my php.ini file
When I start up my wamp I see the following error message:
PHP Startup: Unable to load dynamic library ‘c:/wamp/bin/php/php5.3.0/ext/php_oci8.dll’
I’m able to verify that the above path is correct, and am tempted to say that there’s something wrong with the .dll, but I’m not sure.
Has anyone experienced similar issues?
The Oracle OCI8 driver also requires that the Oracle Instant Client 10gR2 (aka 10.2.x) libraries or newer be installed on the machine PHP is running on. It is recommended you use either the Basic or Basic Lite version depending on if you need the internationalization libraries or not.
Win32 Instant Client Download Page
Win64 Instant Client Download Page
An annotation: I recently had the task of installing PHP 5 on a Windows system with Oracle HTTP Server 10g. PHP <= 5.0 requires an Oracle 8i or 9i client, PHP >= 5.1 requires an Oracle 10gR2 client or above. The Oracle HTTP Server 10g deploys an Oracle 10gR1 client which is not at all supported by PHP 5 (at least on Windows, maybe one can compile by himself...),
but contains PHP 4.3.9 as an Apache module. I couldn't use it: some PHP modules that are required need at least PHP 5.0.
Solution was: return to Oracle HTTP Server from the 9i companion CD while running a 10gR2 database in a separate Oracle Home.

Categories