1

I have seen the other SO questions dealing with the bug in php 5.3 and have php_pdo_mysql enable in the php.ini file located in MAMP/conf/php5.4.4. When I look at the phpInfo, under PDO it only has the sqlite driver enabled. If anyone has any suggestions on how to troubleshoot this further it would be greatly appreciated.

This is the line in question:

$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');

I'm including some additional info as I think it applies to the solutions I've tried so far

try 
{ 
    $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); 
} 
catch(PDOException $ex) 
{ 
    die("Failed to connect to the database: " . $ex->getMessage()); 
} 

I tried replacing all the variable parameters of the PDO object with string values ie. {$host} becomes 'localhost' etc. and got the error message in the catch block with $ex->getMessage() being 'could not find driver'

gherkins
  • 14,603
  • 6
  • 44
  • 70
D_________
  • 563
  • 5
  • 14
  • Please first supply some code. Without context this question is not easy to make sense of. – deceze Jul 04 '13 at 18:42
  • Here is a [bug report](https://bugs.php.net/bug.php?id=47224). Someones states there that you should install `PDO_MYSQL`. At least, it isn't on the list of [predefined constants of PDO](http://de3.php.net/manual/en/pdo.constants.php). – ComFreek Jul 04 '13 at 19:06
  • That's what I don't understand -- I have the php_pdo_mysql piece of the .ini file uncommented but mysql doesn't show up under the PDO portion of phpinfo() – D_________ Jul 04 '13 at 20:22
  • 1
    Uncommenting the options for a module/extension is not the same as enabling it. Depending on what system you're running under, there may be a "managed" way of enabling it (e.g. `phpenmod` under Debian/Ubuntu), but basically it needs to be either compiled in when PHP is built (e.g. using a `USE` flag on Gentoo) or loaded from a `.so`/`.dll` file using the [`extension` ini parameter](http://www.php.net/manual/en/ini.core.php#ini.extension). – IMSoP Jul 04 '13 at 20:27
  • About the "managed" way of enabling modules... I've heard that in MAMP the .ini files are generated on startup so I would assume that there is some sort of config file you can modify. Can anyone confirm this? The documentation on the MAMP website is rather sparse. – D_________ Jul 04 '13 at 21:57

2 Answers2

1

i had to do is : Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' with pdo

sudo apt-get install php5-mysql

sudo /etc/init.d/apache2 restart

=> issues have been resolved

Community
  • 1
  • 1
tiepnv
  • 336
  • 2
  • 9
0

Check out this DSN:

$dsn = 'mysql:dbname=testdb;host=127.0.0.1;charset=utf8';

Instead of MySQL attr init command.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
Paweł Zegardło
  • 298
  • 3
  • 10
  • Are you sure that modified the correct ini file? For example in WAMP Server there are two php.ini files: one for cli mode, second for apache. – Paweł Zegardło Jul 04 '13 at 21:00
  • I did some searching and found another php.ini file under MAMP/bin/php/php5.4.4/conf, opened it up and it was blank... tried pasting the code from the MAMP/conf/php5.4.4, restarted MAMP and it works perfectly. PDO section of phpinfo() now has all of my enabled db's. Don't get me wrong, I'm thrilled its working now, but why? I've always modified the php.ini file in MAMP/conf/php5.4.4. Like I said above, the documentation on the MAMP website is lacking, can anyone shed some light? – D_________ Jul 04 '13 at 22:13
  • I think there is a such as I wrote above. – Paweł Zegardło Jul 04 '13 at 23:28