Problem connecting to postgres with Kohana 3 database module on OS X Snow Leopard

Posted by Bart Gottschalk on Stack Overflow See other posts from Stack Overflow or by Bart Gottschalk
Published on 2010-05-26T16:14:27Z Indexed on 2010/05/26 16:21 UTC
Read the original article Hit count: 416

Filed under:
|
|

Environment:

Mac OS X 10.6 Snow Leopard
PHP 5.3
Kohana 3.0.4

When I try to configure and use a connection to a postgresql database on localhost I get the following error:

ErrorException [ Warning ]: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)

Here is the configuration of the database in /modules/database/config/database.php (note the third instance named 'pgsqltest')

return array
(
'default' => array
(
    'type'       => 'mysql',
    'connection' => array(
        /**
         * The following options are available for MySQL:
         *
         * string   hostname
         * string   username
         * string   password
         * boolean  persistent
         * string   database
         *
         * Ports and sockets may be appended to the hostname.
         */
        'hostname'   => 'localhost',
        'username'   => FALSE,
        'password'   => FALSE,
        'persistent' => FALSE,
        'database'   => 'kohana',
    ),
    'table_prefix' => '',
    'charset'      => 'utf8',
    'caching'      => FALSE,
    'profiling'    => TRUE,
),
'alternate' => array(
    'type'       => 'pdo',
    'connection' => array(
        /**
         * The following options are available for PDO:
         *
         * string   dsn
         * string   username
         * string   password
         * boolean  persistent
         * string   identifier
         */
        'dsn'        => 'mysql:host=localhost;dbname=kohana',
        'username'   => 'root',
        'password'   => 'r00tdb',
        'persistent' => FALSE,
    ),
    'table_prefix' => '',
    'charset'      => 'utf8',
    'caching'      => FALSE,
    'profiling'    => TRUE,
),
'pgsqltest' => array(
    'type'       => 'pdo',
    'connection' => array(
        /**
         * The following options are available for PDO:
         *
         * string   dsn
         * string   username
         * string   password
         * boolean  persistent
         * string   identifier
         */
        'dsn'        => 'mysql:host=localhost;dbname=pgsqltest',
        'username'   => 'postgres',
        'password'   => 'dev1234',
        'persistent' => FALSE,
    ),
    'table_prefix' => '',
    'charset'      => 'utf8',
    'caching'      => FALSE,
    'profiling'    => TRUE,
),
);

And here is the code to create the database instance, create a query and execute the query:

$pgsqltest_db  = Database::instance('pgsqltest');
$query = DB::query(Database::SELECT, 'SELECT * FROM test')->execute();

I'm continuing to research a solution for this error but thought I'd ask to see if someone else has already found a solution. Any ideas are welcome.

One other note is that I know my build of PHP can access this postgresql db since I'm able to manage the db using phpPgAdmin. But I have yet to determine what phpPgAdmin is doing differently to connect to the db than what Kohana 3 is attempting.

Bart

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about snow-leopard