开发者

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

开发者 https://www.devze.com 2022-12-31 22:39 出处:网络
Edits/Additions at bottom... 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 erro

Edits/Additions at bottom...

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,
    'profil开发者_StackOverflow中文版ing'    => 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

///////////// EDIT ONE /////////////

Based on Matt's comment I changed the following in the configuration of the 'pgsqltest' database instance.

from

'dsn'        => 'mysql:host=localhost;dbname=pbeeep',  

to

'dsn'        => 'pgsql:host=localhost;dbname=pbeeep',  

I also changed the execution of the query.

from

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

to

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

Now I get the following error

PDOException [ 0 ]: could not find driver

I'm not sure if this is progress or not but it's more info to share.


My first comment is that you have Kohana configured to use mysql 'type' => 'mysql',. Try updating that for now and get back to us.

0

精彩评论

暂无评论...
验证码 换一张
取 消