PDO - mysql driver problems

Hi all,

I have recently bought iMac for my development work.
I'm working on php developments and I use PDO library for mysql connection.
When I'm trying to connect to DB by using "mysql" driver I'm getting an error: "could not find driver".

How can I solve this problem the easiest way?
I found a lot of stuff in the internet but non of it worked.

Thanks a lot.

iMac, Mac OS X (10.5.3)

Posted on Jun 29, 2008 4:57 AM

Reply
15 replies

Jun 29, 2008 1:12 PM in response to ShurikA

+I also do can work with MySQl through terminal.+
This just means that you have mySQL installed. Can you access a database using PHP but without using PDO? Something like this:

<?php
$hostname = "localhost";
$database = "a database name";
$username = "root"; // or whatever
$password = "your password here";
$connection = mysql_pconnect($hostname, $username, $password) or trigger(mysql_error(), E-USER_ERROR);
?>

Does this return an error?
If you haven't changed anything then PHP will be looking for the mysql socket in the wrong place (/var/mysql/mysql.sock instead of /tmp/mysql.sock). Also, the PDO manual mentions that you need to change the php.ini file.

Jun 29, 2008 2:46 PM in response to Joaquim Lopes

This one also does work:

public function __construct(){
$registry = IibRegistry::getInstance();

$siteConf = $registry->getArray(IIB_SITE_CONFIG);
//print_r($siteConf);
//set all needed configuration.
$this->_dbHost = array_key_exists('db_host', $siteConf) ? $siteConf['db_host'] : 'localhost';
$this->_dbName = array_key_exists('db_name', $siteConf) ? $siteConf['db_name'] : '';
$this->_dbUser = array_key_exists('db_user', $siteConf) ? $siteConf['db_user'] : '';
$this->_dbPass = array_key_exists('db_pass', $siteConf) ? $siteConf['db_pass'] : '';
$this->_tablePrefix = array_key_exists('table_prefix', $siteConf) ? $siteConf['table_prefix'] : '';

// foreach(PDO::getAvailableDrivers() as $driver)
// {
// echo $driver.'
';
// }

parent::__construct('sqlite:host='.$this->_dbHost.';dbname='.$this->_dbName.'', $this->_dbUser, $this->_dbPass);//, array(PDO::ATTR_PERSISTENT => true));
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('IibStatement', array($this)));
//$this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}

Jun 30, 2008 10:37 AM in response to ShurikA

It's possible (and fairly easy) to compile a PHP module to add into an existing installation. Rather than doing "./configure", "make", "sudo make install" in the PHP source directory, you can go into, say, ext/pdo_mysql, type "phpize" and then do the "./configure", "make", "sudo make install" bit. Then you just enable the module in /etc/php.ini.

There are a few extra problems with PDO_mysql specifically, as the Apache/PHP install in Leopard is 64-bit, so it can be a little tricky to get the MySQL client library to play ball.

At the risk of being accused of spamming, I just blogged about this very issue (building PDO_mysql for Leopard):

http://gidden.net/tom/2008/06/30/mysql-and-pdo-on-os-x-leopard-intel/

The article assumes experience in building MySQL and PHP from source.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

PDO - mysql driver problems

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.