I'm trying to learn the Symfony framework for PHP but having issues with the command line version of php.
When trying to create the database tables:
./symfony doctrine:insert-sql
I'm getting the following error:
Couldn't locate driver named mysql
This is only an issue with the command line version of php. I've had doctrine working no problem.
After quickly reading up on the problem, it seems I need to enable PDO_MYSQL for the CLI installation of php. I've looked in the php.ini file and there does not appear to be a relevant entry for it.
Is there any easy way to make the CLI version use exactly the same configuration of my LAMPP configuration, in order to minimise complications in the future?
Any advice would be greatly appreciated.
Thanks.
I'm using ubuntu
+mysql
(individual install non-lamp) and php cli
via apt
:
sudo apt-get install php5-cli
PDO is installed by default but the appropriate db driver (mysql
in my case) wasn't installed. This can be verified from the command line php --ri pdo
which results in:
PDO support => enabled
PDO drivers => [ blank ]
To rectify this for mysql
, install the php5-mysql
module via
sudo apt-get install php5-mysql
Obviously, do this after you've installed php5-cli
. If you're using another db (e.g. postgres
or odbc
) look for the appropriate module name via
sudo apt-cache search php5
Sorry, crossposted from my answer here.
check the php.ini in your apache folder and copy the PDO information to the php.ini in your php folder.
In my lampp configuration I just have 'extension=pdo.so' in php.ini
I think these answers are a bit old. Correct answer would be sudo apt-get install php-mysql. Executing php5-mysql would result in no package found, specially on machines which has php7-cli installed. As mentioned problem is that though PDO support is enabled, no driver installed. I simply resolved it by executing the above command.