Tuesday, December 6, 2011

Re: Cake PHP 2.0.4 - "Cake is NOT able to connect to the database."

I found the problem by running this script with the command line php:

<?php
$dsn = 'mysql:host=localhost;dbname=test_db';
$username = 'myuser';
$password = 'mypasswd';
$options = array(
         PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
         ); 

         $dbh = new PDO($dsn, $username, $password, $options) or die(mysql_error);;
echo "\nConnected to Database\n"; 
?>


Even though I specified "pdo_mysql.default_socket = /var/tmp/mysql.sock" in php.ini, by default mysql PDO seems to look for /tmp/mysql.sock. 

The solution is to specify the socket in the database.php:

      'unix_socket' => '/var/tmp/mysql.sock',

Hopefully someone finds this info useful.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: