I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver
.
This is the specific line of code it is referring to:
$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)
DB_HOST
, DB_NAME
, DB_USER
, and DB_PASS
are constants that I have defined. It works fine on the production server (and on my previous Ubuntu Server setup).
Is this something to do with my PHP installation?
Searching the internet has not helped, all I get is experts-exchange and examples, but no solutions.
ghbarratt
11.4k4 gold badges41 silver badges41 bronze badges
asked May 17, 2010 at 20:57
8
You need to have a module called pdo_mysql. Looking for following in phpinfo(),
pdo_mysql
PDO Driver for MySQL, client library version => 5.1.44
answered May 17, 2010 at 21:33
ZZ CoderZZ Coder
74.3k29 gold badges136 silver badges169 bronze badges
10
The dsn in your code reveals you are trying to connect with the mysql driver. Your error message indicates that this driver is unavailable.
Check that you have the mysql extension installed on your server.
In Ubuntu/Debian you check for the package with:
dpkg --get-selections | grep php | grep mysql
Install the php5-mysql package if you do not have it.
In Ubuntu/Debian you can use:
- PHP5:
sudo apt-get install php5-mysql
- PHP7:
sudo apt-get install php7.0-mysql
Lastly, to get it working, you will need to restart your web-server:
- Apache:
sudo /etc/init.d/apache2 restart
- Nginx:
sudo /etc/init.d/nginx restart
answered Nov 10, 2011 at 5:21
ghbarrattghbarratt
11.4k4 gold badges41 silver badges41 bronze badges
2
Update: newer versions should use php-sqlite3
package instead of php5-sqlite
. So use this, if you are using a recent ubuntu version:
sudo apt-get install sqlite php-sqlite3
Original answer to question is here:
sudo apt-get install sqlite php5-sqlite
sudo /etc/init.d/apache2 restart
If your phpinfo() is not showing the pdo_sqlite line (in my case, on my Ubuntu Server), you just need to run the lines above and then you’ll be good to go.
answered Aug 27, 2010 at 18:39
8
For newer versions of Ubuntu that have PHP 7.0 you can get the php-mysql
package:
sudo apt-get install php-mysql
Then restart your server:
sudo service apache2 restart
answered Aug 19, 2016 at 6:28
ThomasAFinkThomasAFink
1,24914 silver badges25 bronze badges
1
I had the same issue. The solution depends on OS. In my case, i have debian, so to solve it:
- Updated my php version from (php5 to php7)
-
Install php-mysql and php7.0-mysql
apt-get install php-mysql apt-get install php7.0-mysql
-
I edited my
php.ini
locate at /etc/php/7.0/apache2/php.iniuncomment the line : extension=php_pdo_mysql.dll
-
Then restart apache:
service apache2 restart
This solves my problem
answered Jun 5, 2017 at 1:26
onlymeonlyme
3,7562 gold badges22 silver badges17 bronze badges
1
On my Windows machine, I had to give the absolute path to the extension dir in my php.ini:
extension_dir = "c:php5ext"
fvrghl
3,6325 gold badges28 silver badges36 bronze badges
answered Jun 10, 2013 at 22:41
berdziberdzi
2513 silver badges2 bronze badges
2
Check if the module is available with php -m | grep pdo_mysql
.
If not, for PHP 7.2, you can install relevant package with sudo apt install php7.2-mysql
.
Use similar command on other PHP versions and package managers.
answered Jul 4, 2019 at 5:30
PratikPratik
9591 gold badge14 silver badges20 bronze badges
On Ubuntu just execute
sudo apt-get install php5-mysql
answered Apr 16, 2013 at 13:22
2
sudo apt-get install php-mysql
worked well on ubuntu and php 7
answered May 12, 2016 at 9:11
1
When adding these into your php.ini ensure the php_pdo.dll reference is first before the db drivers dlls otherwise this will also cause this error message too. Add them like this:
[PHP_PDO]
extension=php_pdo.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
Luís Cruz
14.8k16 gold badges67 silver badges100 bronze badges
answered Nov 17, 2014 at 23:33
1
for Windows 8.1/10 in :\php.ini file you should uncomment line «extension=pdo_mysql»
answered Dec 19, 2017 at 16:18
Did you check your php.ini (check for the correct location with phpinfo()) if MySQL and the driver is installed correctly?
answered May 17, 2010 at 21:08
cemcem
3,3011 gold badge18 silver badges23 bronze badges
1
For PHP 5.5
on CentOS
I fixed this by installing the php55-mysqlnd
package.
sudo yum -y install php55w-mysqlnd # For Webtatic
sudo yum -y install php55u-mysqlnd # For Remi
For help installing, write a comment as it depends on the way PHP is installed on your system. Available repo’s are webtatic
and remi
.
answered Jul 23, 2014 at 9:22
SimonWSimonW
6,1154 gold badges32 silver badges39 bronze badges
I had the same problem during running tests with separate php.ini. I had to add these lines to my own php.ini file:
[PHP]
extension = mysqlnd.so
extension = pdo.so
extension = pdo_mysql.so
Notice: Exactly in this order
answered Jul 23, 2016 at 15:04
FacedownFacedown
1921 gold badge2 silver badges10 bronze badges
0
Check if extension_dir in php configuration file set correctly. Try to comment/uncomment some extensions and see if it’s reflected on phpinfo().
If it doesn’t then either php config file cannot be loaded (wrong location) extension_dir is commented or set to the wrong location.
answered Aug 18, 2012 at 14:02
hsergehserge
8951 gold badge9 silver badges12 bronze badges
In my case my DSN string was incorrect, specifically it did not contain mysql://.
I would have expected a different error message, perhaps something like ‘DSN string does not specify driver/protocol.’
Adding mysql://
to the beginning of the DSN string resolved the issue.
answered Jun 21, 2012 at 16:38
I spent the last day trying to figure out why I was getting the following error. I am running Ubuntu 14.04.
The Problem:
I noticed that my PHP-CLI version was running php7.0 but php_info() (the web version) was displaying php 5.5.9. Even though php_info() said pdo was enabled, using the command line (CLI) wasn’t recognizing the pdo_mysql command. It turns out that mysql was enabled for my old version but not the CLI version. All I did was install mysql for php7.0 and it was able to work.
This is what worked:
To check the version:
php -v
To install mysql for php7.0
sudo apt-get install php7.0-mysql
1) make sure your CLI version is the same as your web version
2) If they are different, make sure your CLI version has the mysql plug-in since it doesn’t come with it as a default.
answered Jan 4, 2017 at 20:31
Incorrect installation of PHP was being called
I was experiencing the same problem. And I hope this would help someone who is having a similar issue as me.
Scenario
OS = Windows 10
Platform = XAMPP
PHP Version = 7 (Multiple Version seem to have been installed in the PC)
I created phpinfo.php
file in the public
folder and run the phpinfo()
to look for the location of my php.ini
file.
PHP.ini Location = c:xamppphpphp.ini
Problem
Calling c:xampphtdocs> php -v
returned PHP 7.2.3
but phpinfo.php
showed PHP 7.2.2
.
Solution
Instead of calling
php artisan migrate:install
which gave me this error, I used
c:xamppphpphp artisan migrate:install
and it worked.
answered Sep 21, 2018 at 10:21
RealSollyMRealSollyM
1,5201 gold badge22 silver badges35 bronze badges
The problem is a missing php to mysql library. In CentOs i fixed it by running
# yum install php-mysql
and then restarting apache with # /bin/systemctl restart httpd.service
Note that the naming is slightly different from debian/ubuntu based distros, php->php5 and httpd->apache2.
answered Dec 8, 2015 at 6:36
I extremely recommend mysqllnd
instead of mysql
because of you would have a lot of problems like number converting and bit type evaluates problem with mysql
extension.
on ubuntu install mysqllnd
with following command:
sudo apt-get install php5-mysqlnd
answered Sep 17, 2016 at 17:21
MSSMSS
3,48224 silver badges28 bronze badges
In my case, I was using PDO with php-cli, and it worked fine.
Only when I tried to connect from apache, I got the «missing driver» issue, which I didn’t quite understand.
A simple apt-get install php-mysql
solved it. (Ubuntu 16.04 / PHP7. credits go to the selected answer & Ivan’s comment)
Hope it can help.
answered Oct 31, 2016 at 14:46
BalmipourBalmipour
2,9851 gold badge24 silver badges27 bronze badges
PHP Fatal error: Uncaught PDOException: could not find driver
I struggled and struggled with «apt install php-mysql php7toInfinity and don’t forget sqlite-what-ever’s» and just could not get rid of this error message until I went back to basics and reset the file-permissions on the web-site in question.
These 3 commands reset file and folder permissions on the web-site and got it to work again.
cd /var/www/web-site-name.com/web/
# find (sub) directories and change permissions
find . -type d -exec chmod 755 {} ;
# find files and change permissions
find . -type f -exec chmod 664 '{}' ;
answered Aug 18, 2019 at 18:48
SamTzuSamTzu
1671 silver badge7 bronze badges
I Fixed this issue on my Debian 6.
Normally I just had installed php5-common
package. After installation, you have to restart your web server (apache or nginx depending on which one you installed).
Then I just do an lsof
on the apache process id (lsof -p process_id
) as followed :
sudo lsof -p 1399 #replace 1399 by your apache process id
apache2 1399 root mem REG 254,2 80352 227236 /usr/lib/php5/20090626/xmlrpc.so
apache2 1399 root mem REG 254,2 166496 227235 /usr/lib/php5/20090626/suhosin.so
apache2 1399 root mem REG 254,2 31120 227233 /usr/lib/php5/20090626/pdo_mysql.so
apache2 1399 root mem REG 254,2 100776 227216 /usr/lib/php5/20090626/pdo.so
apache2 1399 root mem REG 254,2 135864 227232 /usr/lib/php5/20090626/mysqli.so
As you can see above, the modules are installed on a file path not known or guided by common library path: /usr/lib/php5/20090626/
. For your installation, it may be different, but only the path of pdo_mysql.so, pdo.so, mysqli.so. So, this is why Drupal or any other php engine couldn’t find the library and shows that error: PDOException: could not find driver
I just don’t know why it is installed on such a weird path, for me it’s just a bug in the library package installation script in debian 6.
I solved the issue by creating a symbolic for all the files under /usr/lib/php5/20090626/
to
/usr/lib/php5/
with this command :
ln -s /usr/lib/php5/20090626/* /usr/lib/php5/
fvrghl
3,6325 gold badges28 silver badges36 bronze badges
answered Nov 8, 2012 at 17:20
douggynixdouggynix
1412 silver badges2 bronze badges
1
$DB_TYPE = 'mysql'; //Type of database<br>
$DB_HOST = 'localhost'; //Host name<br>
$DB_USER = 'root'; //Host Username<br>
$DB_PASS = ''; //Host Password<br>
$DB_NAME = 'database_name'; //Database name<br><br>
$dbh = new PDO("$DB_TYPE:host=$DB_HOST; dbname=$DB_NAME;", $DB_USER, $DB_PASS); // PDO Connection
This worked for me.
fvrghl
3,6325 gold badges28 silver badges36 bronze badges
answered Jun 3, 2013 at 3:18
1
I faced the same issue after I removed the php5 package (that includes all the drivers as well) in order to install php7 package. I actually installed php7 package without a mysql module.
I managed to solve it by typing in the terminal:
1) $ apt-cache search php7
which lists all the modules, looking through the modules I found,
php7.0-mysql — MySQL module for PHP
2) $ sudo apt-get install php7.0-mysql
That’s it. It worked for me in my linux system.
(use the appropriate php version, yours could be php5)
answered May 10, 2016 at 12:38
RoshimonRoshimon
1,97118 silver badges16 bronze badges
Just one other thing to confirm as some people are copy/pasting example code from the Internet to get started. Make sure you have MySQL entered here:
... $dbh = new PDO ("mysql: ...
In some examples this shows
$dbh = new PDO ("dblib ...
Dimitar
4,3424 gold badges31 silver badges47 bronze badges
answered Jun 29, 2016 at 3:49
For those using Symfony2/3 and wondering why you’re getting this error. If you’re using «mapping_types», you might encounter this error. The reason is that «mapping_types» is placed at the wrong level. For instance :
doctrine:
dbal:
mapping_types:
set: string
This «mapping_types» must be placed at this level :
doctrine:
dbal:
#To counter the error caused by 'mapping_types'
connections:
default:
server_version: %database_server_version%
mapping_types:
set: string
I hope this helps
I found the solution here : https://github.com/doctrine/DoctrineBundle/issues/327
answered Feb 17, 2017 at 20:07
aneth101aneth101
5095 silver badges9 bronze badges
Everywhere I go I read that the path of extension_dir
should be changed from ext
to an absolute path. It worked for me. However, when trying to build a server of my colleague’s PC, I had to let the value to ext
instead of putting an absolute path.
If you did put an absolute path and it does the extension is still not found, considerer trying both with the absolute path and ext
.
answered Feb 13, 2018 at 10:42
papillonpapillon
1,7472 gold badges18 silver badges36 bronze badges
Check correct path in extension_dir in you phpinfo().
answered May 29, 2019 at 19:42
Had the same issue, because I forgot to go into my virtual machine. If I go to my local directory like this:
cd /www/homestead/my_project
php artisan migrate
that error will appear. But it works on my virtual machine
cd ~/homestead
vagrant ssh
cd /www/homestead/my_project
php artisan migrate
answered Jun 21, 2019 at 7:16
AdamAdam
25.3k22 gold badges152 silver badges238 bronze badges
-
Главная
Список форумов
Ошибки Open Server
-
Поиск
-
- Текущее время: 14 июн 2023, 05:06
- Часовой пояс: UTC+03:00
-
santex85
- Сообщения: 2
- Зарегистрирован: 18 апр 2016, 12:27
-
Максим
- Сообщения: 6005
- Зарегистрирован: 11 дек 2010, 20:29
-
orogastus
- Сообщения: 3
- Зарегистрирован: 23 янв 2015, 21:35
Re: Ошибка Uncaught exception ‘PDOException’ with message ‘could not find driver’
Непрочитанное сообщение
orogastus » 10 сен 2018, 09:45
Вот такая ошибка вылазит:
Fatal error: Uncaught exception ‘PDOException’ with message ‘could not find driver’ in C:OSPaneldomainsC9includesetting.php:9 Stack trace: #0 C:OSPaneldomainsC9includesetting.php(9): PDO->__construct(‘sqlsrv:server=8…’, ‘sa’, ‘m128634!’) #1 C:OSPaneldomainsC9script-head.php(3): include_once(‘C:OSPaneldoma…’) #2 C:OSPaneldomainsC9index.php(1): include(‘C:OSPaneldoma…’) #3 {main} thrown in C:OSPaneldomainsC9includesetting.php on line 9
скриншот: все подключено раскомментировано: http://prntscr.com/kskl0e
помогите, куда копать?
include_once(«function.php»);
$sql = new PDO(«sqlsrv:server=».MSSQL_HOST.»; Database=».MSSQL_DB.»»,MSSQL_USER,MSSQL_PASS);
$api = new API(true);
$ip = $_SERVER[‘REMOTE_ADDR’];
вот что там
-
orogastus
- Сообщения: 3
- Зарегистрирован: 23 янв 2015, 21:35
-
Максим
- Сообщения: 6005
- Зарегистрирован: 11 дек 2010, 20:29
Re: Ошибка Uncaught exception ‘PDOException’ with message ‘could not find driver’
Непрочитанное сообщение
Максим » 07 сен 2021, 18:47
voron121, вы ничего не можете понять, т.к. не читали или невнимательно прочитали руководство пользователя. В противном случае вы могли бы знать, что корректная среда окружения доступна только в тех программах, что запускаются из меню Open Server. А когда вы запускаете свои обычные программы в Windows они естественно не видят переменные окружения Open Server и вы получаете то, что получаете.
На будущее, предвидя ваше следующее непонимание, замечу, что если вы меняете версию любого модуля в настройках, то меняется и окружение. Поэтому программы, запущенные из меню ранее, необходимо перезапускать, чтобы они увидели обновлённое окружение. Всё это указано в руководстве.
Привет
Пытаюсь выполнить данную команду из корня проекта zf2:vendorbindoctrine-module orm:validate-schema
Результат работы команды:
[Mapping] OK - The mapping files are correct.
[PDOException]
could not find driver
orm:validate-schema
Юзал поиск, но толкового ничего не нашел.
Были такие варианты, как проблемы с конфиг файлом. Вот мой конфиг:
<?php
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' =>'DoctrineDBALDriverPDOMySqlDriver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => '',
'dbname' => 'ZF2_Test',
)
)
),
),
);
Все путем + есть другой модуль, который работает с ORM Doctrine и он работает без каких-либо проблем.
Были варианты с неподключенным расширением extension=php_pdo_mysql.dll
в php.ini файле. Он у меня подключен в Php.ini + phpinfo() показывает, что PDO включено.
В итоге так и не нашел решения данной проблемы. Что может вызывать эту ошибку и как ее решать?
Спасибо
I am newbie for Ubuntu and I was trying to run LAMP.
I installed MySQL, and PDO extensions. When I show the PHP config (with phpinfo()
) it shows:
Configuration File (php.ini) Path: /etc/php5/apache2
Also I see mysql and pdo_mysql tables in the config output.
locate pdo_mysql.so
giving: /usr/lib/php5/20090626+lfs/pdo_mysql.so
locate mysql.so
giving:
/usr/lib/perl5/auto/DBD/mysql/mysql.so
/usr/lib/php5/20090626+lfs/mysql.so
/usr/lib/php5/20090626+lfs/pdo_mysql.so
/usr/lib/pyshared/python2.7/_mysql.so
/usr/lib/python2.7/dist-packages/_mysql.so
in the php.ini
file I enabled the extensions like this:
extension=/usr/lib/php5/20090626+lfs/mysql.so
extension=/usr/lib/php5/20090626+lfs/pdo_mysql.so
But that does not help
Then I enabled
extension=mysql.so
extension=pdo_mysql.so
still the same, no result,
after any changes I am restarting Apache2 with service apache2 restart
But still PHP can not locate PDO for opening connection.
So how can I get it work?
# Проблема
Любая попытка взаимодействия с базой данной завершается ошибкой:
[IlluminateDatabaseQueryException] could not find driver
PDOException(code: 0): could not find driver at /Illuminate/Database/Connectors/Connector.php
# Причина
В окружении не установлены или не подключены расширения для базы данных.
Посмотреть список установленных модулей можно командой php -m
# Решение
Установить расширение php-pdo и
php-mysql для MySQL
php-pgsql для PostgreSQL
php-sqlite для SQLite
Для конкретной версии, например, 8.1:
Или автоматически для текущей:
Возможно понадобится перезапуск web-сервера. Обычно больше ничего не требуется, но если модули по какой-то причине
не подключились автоматически, то можно активировать вручную:
# Решение для Windows
Для Windows смысл тот же,
необходимо скачать
dll в директорию ext с расширениями,
но скорей всего необходимые модули уже присутствуют в сборке,
осталось только их подключить в php.ini
Для этого необходимо удалить символ ; в начале строк: