简体   繁体   English

PDO_mysql无法与doctrine2和MAMP一起使用

[英]PDO_mysql not working with doctrine2 and MAMP

For some reason, why I attempt to connect to my local mysql database using doctrine. 由于某些原因,为什么我尝试使用主义连接到本地mysql数据库。 I get the following error: 我收到以下错误:

Could not create database for connection named `new_db` could not find driver

My PHPinfo file tells me that pdo_mysql is running, is version 5.5.38 and is supposedly located here: /Applications/MAMP/tmp/mysql/mysql.sock (however I can't find mysql.sock in that directory). 我的PHPinfo文件告诉我pdo_mysql正在运行,版本为5.5.38,可能位于以下位置:/Applications/MAMP/tmp/mysql/mysql.sock(但是我在该目录中找不到mysql.sock)。

The php.ini file according to the php info file is located here: 根据php信息文件的php.ini文件位于此处:

Configuration File (php.ini) Path   /Applications/MAMP/bin/php/php5.6.1/conf
Loaded Configuration File   /Library/Application Support/appsolute/MAMP PRO/conf/php.ini

My command line (which has been configured to point to the same version of PHP as mamp (in theory) states that it is using the following php.ini 我的命令行(已配置为指向与mamp相同版本的PHP(从理论上讲),它表明它正在使用以下php.ini

Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.6.1/conf
Loaded Configuration File:         /Applications/MAMP/bin/php/php5.6.1/conf/php.ini

I'm unsure why phpinfo has a different 'Loaded configuration file' entry and I wonder if this is the problem, however I'm unsure how to change that. 我不确定为什么phpinfo有一个不同的“已加载配置文件”条目,并且我想知道这是否是问题,但是我不确定如何更改它。 Interestingly though both files state that pdo_mysql should be loaded. 有趣的是,尽管两个文件都声明应加载pdo_mysql。

Annoyingly, in spite of all php.ini files I can find stating that pdo_mysql is loaded when I type php -m | grep -G PDO -i 烦人的是,尽管有所有的php.ini文件,我仍然可以找到说明,当我键入php -m | grep -G PDO -i时,pdo_mysql已加载php -m | grep -G PDO -i php -m | grep -G PDO -i I only see: php -m | grep -G PDO -i我只看到:

PDO
pdo_sqlite

I'm at a loss as to why pdo_mysql isn't loading as it really seems that it should be. 我不知道为什么pdo_mysql没有加载,因为它确实应该加载。

I am running MAMP Pro on Mac OSx Yosemite. 我在Mac OSx Yosemite上运行MAMP Pro。

Edit: As requested, here is the connection string which is auto-generated by symfony: 编辑:根据要求,这是由symfony自动生成的连接字符串:

{ parameters: { database_driver: pdo_mysql, database_host: 127.0.0.1, database_port: 3306, database_name: new_db, database_user: dbuser, database_password: dbpass, mailer_transport: smtp, mailer_host: 127.0.0.1, mailer_user: null, mailer_password: null, locale: en, secret: thisisnotmysecret, debug_toolbar: true, debug_redirects: false, use_assetic_controller: true, database_path: null } }

Update: After attempting to connect without the framework I got the following error: 更新:在没有框架的情况下尝试连接后,出现以下错误:

[20-Oct-2014 17:15:44 Europe/London] PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20121212/pdo_mysql.so' - dlopen(/Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20121212/pdo_mysql.so, 9): image not found in Unknown on line 0 [2014年10月20日17:15:44欧洲/伦敦] PHP警告:PHP启动:无法加载动态库'/Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug- non-zts-20121212 / pdo_mysql.so'-dlopen(/Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20121212/pdo_mysql.so,9):图片在第0行的“未知”中找不到

This is irritating as the folder it SHOULD point to is "no-debug-non-zts-20131226" and not "no-debug-non-zts-20121212" Does anyone know how to update this path? 这很令人讨厌,因为它应该指向的文件夹是“ no-debug-non-zts-20131226”,而不是“ no-debug-non-zts-20121212”。有人知道如何更新此路径吗?

It turned out that Mamp pro's default php.ini file was wrong. 事实证明Mamp pro的默认php.ini文件是错误的。 It thought that the extension dir should be: 它认为扩展目录应该是:

extension_dir = "/Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20121212/" extension_dir =“ /Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20121212/”

When it should actually have been: 实际应该是什么时候:

extension_dir = "/Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20131226/" extension_dir =“ /Applications/MAMP/bin/php/php5.6.1/lib/php/extensions/no-debug-non-zts-20131226/”

I updated the file and now it works like a charm :) 我更新了文件,现在它就像一个魅力:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM