Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 7 RC3: How to install missing MySQL PDO

I am trying to setup webserver with PHP 7 RC3 + Nginx on Ubuntu 14.04 (for test purposes).

I installed Ubuntu in Vagrant using ubuntu/trusty64 and PHP 7 RC 3 from Ondřej Surý (https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0).

I can not find the way to install MySQL PDO (PHP sees PDO class but not anything related to MySQL, like PDO::MYSQL_ATTR_DIRECT_QUERY etc.)

Looks like there is no lib php7.0-mysql (by analogy with standard php5-mysqlnd and php7.0-fpm etc. from Ondřej)

Section PDO in phpinfo():

PDO support      enabled PDO drivers      no value 

How can I get it?

like image 326
SmxCde Avatar asked Sep 22 '15 23:09

SmxCde


People also ask

How do I install PDO drivers?

Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.

How do I know if PDO is enabled in PHP?

if ( extension_loaded('pdo_<database type here>') ) { // e.g., pdo_mysql ....... } Show activity on this post. I appreciate the support and all the upvotes I still get, but please check Salman Abbas's answer for the proper way to do this. Was going to suggest defined() but PDO switched to class constants.

Is PDO better than MySQLi?

Both MySQLi and PDO have their advantages: PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries.


1 Answers

For thoses running Linux with apache2 you need to install php-mysql

apt-get install php-mysql 

or if you are running ubuntu 16.04 or higher just running the following command will be enought, no need to edit your php.ini file

apt-get install php7.2-mysql 

If you are running ubuntu 15.10 or below:

Edit your php.ini file, it's located at /etc/php/[version]/apache2/php.ini and search for pdo_mysql you might found something like this

;extension=pdo_mysql.so 

Change it to this

extension=pdo_mysql.so 

Save the file and restart apache

service apache2 restart 

Check that it's available in your phpinfo()

like image 68
Angel115 Avatar answered Sep 29 '22 18:09

Angel115