PDOExceptionMessage:could not find driver - php

I have just started learning PHP and Mysql and I have a problem when I run php file.
error :could not find driver
This is version that I am using:
I tried to follow answers of question that similar but still can not solve the problem.

It appears you have a simple typographical error in your code. You defined your DSN with the string msql:dbhost=localhost...
But you should use mysql:dbhost=localhost...
See http://php.net/manual/en/ref.pdo-mysql.connection.php for reference docs on the MySQL DSN format.
You have installed php-pdo but you might also need either php-mysql or php-mysqlnd (prefer the latter).
You can check by running php -i | less to give a lengthy report of all the extensions currently installed. Look for the "PDO" section, and confirm that the mysql driver is among the drivers installed:
PDO
PDO support => enabled
PDO drivers => sqlite, mysql, sqlite2
If it does, it should be followed by a "pdo_mysql" section. Mine looks like this:
pdo_mysql
PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.8-dev - 20102224 - $Id: 731e5b87ba42146a687c29995d2dfd8b4e40b325 $
Directive => Local Value => Master Value
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock
If you don't have the pdo_mysql section, you should install the corresponding yum package for it:
sudo yum install php-mysqlnd

Related

How to enable sqlsrv - PDO drivers in xampp ubuntu?

Error : PDOException could not find driver
Actually I am facing error this while working with laravel and mssql .
For that purpose I want enable sqlsrv in PDO drivers .
PDO Driver
In this image PDO drivers contain mysql, pgsql, sqlite but not sqlsrv .
So How I can fix it ?
I guess your PHP environment doesn't have PDO extension installed.
To install pdo extension, open terminal and type the below command.
First check which version of PHP is installed, to check the PHP version, type below command :
$ php -v
Suppose you have php7.1 installed, then to install pdo for your version type below
$ sudo apt-get install php7.1-pdo
Restart you apache server :
$ sudo service apache2 restart
See below snap:
After entering the command, press tab to see all the possible commands as shown in the snapshot.

Trying to add the firebird extension to PDO with no luck. I have a RHEL7 server

I've been trying to add the Firebird extension to PDO with no luck. I have a RHEL7 server, I ran ./configure --with-firebird successfully, ran the make command, and make install successfully.
If I type
php -i | grep PDO
I get the following:
PDO
PDO support => enabled
PDO drivers => firebird, sqlite
PDO_Firebird
PDO Driver for Firebird/InterBase => enabled
PDO Driver for SQLite 3.x => enabled
However, when going to my site's phptest.php file it only shows
mysql
sqlite
I guess I'm missing one last step, but I don't know what.
Try running slightly different command
./configure --with-firebird --with-pdo-firebird
Then find phph.ini (or the file that acts like that in Linux platform) and enable (de-comment?) the line like extension=php_pdo_firebird.dll ( in Linux it probably would be like libphp_pdo_firebird.so or something, see for the specific files your building process generate).
See also:
http://php.net/manual/en/ref.pdo-firebird.php
Enable PHP Firebird connection

Laravel 5.1/Homestead PDOException

I am learning Laravel and migrations. I have installed Homestead successfully and everything is be up and running — MySQL included — until I give my first
php artisan migrate
and the shell outputs
[PDOException]
could not find driver
so I connect to the virtual machine via SSH and try to install the PHP extensions required to work with the database, but apt-get detects I have the latest driver version already installed. Then I check to see if PDO is working, so I type php -i | grep PDO and everything looks good:
PDO
PDO support => enabled
PDO drivers => mysql, pgsql, sqlite
PDO Driver for MySQL => enabled
PDO Driver for PostgreSQL => enabled
PDO Driver for SQLite 3.x => enabled
I am out of ideas, what could possibly go wrong?

PDO-dblib mssql installation on a mac

I'm using zend framework, and I have to connect to a microsoft sql db 2005. I've installed all the needed packages through the packet manager (homebrew) following (this tutorial), I've successfully downloaded the version of php5.5 with pdo_dblib. Then the problem started.
Is the php installation valid for Zend framework and zend studio too? Since, the error that I was getting when trying to connect to the db hasn't changed at all so there must be a mistake;
When I run:
php -i | grep -i pdo
The output is:
API Extensions => mysqli,pdo_mysql,mysql
PDO
PDO support => enabled
PDO drivers => mysql, sqlite
pdo_mysql
PDO Driver for MySQL => enabled
pdo_mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
pdo_sqlite
PDO Driver for SQLite 3.x => enabled
So, where is my new installation with php 5.5 and pdo-dblib and mssql?
I'm quite confused...
PS: I'm running OSX 10.9
I've found a tutorial which explains how to link the new version of php. Specifically what is interesting of it is in those two lines of code:
nano ~/.bash_profile
export PATH="$(brew --prefix josegonzalez/php/php55)/bin:/usr/local/bin:$PATH"
now the command:
php -i | grep -i pdo
gives the following output (with pdo dblib):
API Extensions => mysqli,pdo_mysql,mysql
PDO
PDO support => enabled
PDO drivers => dblib, mysql, odbc, sqlite
pdo_dblib
PDO Driver for FreeTDS/Sybase DB-lib => enabled
pdo_mysql
PDO Driver for MySQL => enabled
pdo_mysql.default_socket => /tmp/mysql.sock => /tmp/mysql.sock
PDO_ODBC
PDO Driver for ODBC (unixODBC) => enabled
pdo_sqlite
PDO Driver for SQLite 3.x => enabled

php code to test pdo is available?

I want to use PDO but I'm not sure whether my hosting has set it up properly.
How can I test, in PHP, whether it is setup and working for MySQL?
PDO is always installed for php 5.1+. You can check for specific db drivers that are installed or not using phpinfo(); You could try to check for specific drivers using #Mark Baker idea and checking for specific constants;
var_dump(defined(PDO::MYSQL_ATTR_LOCAL_INFILE)); // mysql
var_dump(PDO::FB_ATTR_TIME_FORMAT)); // firebird
Note that not all drivers have specific constants defined so phpinfo() remains best solution.
Using command line you can check using:
$ php -m
As an alternative of phpinfo() you can use:
extension_loaded ('PDO' ); // returns boolean
// or
extension_loaded('pdo_mysql');
// or get all extensions and search for a specific one
get_loaded_extensions();
Aside from using phpinfo() to see if it's correctly listed
if (!defined('PDO::ATTR_DRIVER_NAME')) {
echo 'PDO unavailable';
}
Try this
print_r(PDO::getAvailableDrivers());
should give applications supported by PHP
Array ( [0] => mysql [1] => sqlite )
Using command line, for PDO:
php -m|grep -i pdo
For PDO with MySQL support:
php -m|grep -i pdo_mysql
To install php mysql support, search for the package name (Ubuntu):
apt-cache search php5*|grep mysql
And install it if not already did (Ubuntu):
sudo apt-get install php5-mysql
Create a file that contains
<?php
phpinfo();
?>
It will show you if PDO (and other features are enabled)
For Windows servers, I've found the following useful for checking which PDO extensions are loaded from the command prompt:
php -m|findstr -i pdo_
On my system, that command nets me the following results:
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite

Categories