在 OS X Snow Leopard 上使用 Kohana 3 数据库模块连接到 postgres 时出现问题

发布于 2024-09-03 01:36:43 字数 3393 浏览 3 评论 0原文

底部编辑/添加...

环境:

Mac OS X 10.6 Snow Leopard
PHP 5.3
Kohana 3.0.4

当我尝试在本地主机上配置和使用与 postgresql 数据库的连接时,出现以下错误:

ErrorException [警告]:mysql_connect():[2002]没有这样的文件或目录(尝试通过unix:///var/mysql/mysql.sock连接)

这里是/modules/database/config/中数据库的配置database.php(注意名为“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,
),
);

这是创建数据库实例、创建查询并执行查询的代码:

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

我正在继续研究此错误的解决方案,但我想我会要求看看其他人是否已经找到了解决方案。欢迎任何想法。

另一件事是,我知道我的 PHP 版本可以访问这个 postgresql 数据库,因为我可以使用 phpPgAdmin 管理该数据库。但我还没有确定 phpPgAdmin 连接数据库的方式与 Kohana 3 尝试的方式不同。

Bart

///////////// 编辑一个 //////////////

根据 Matt 的评论,我在“pgsqltest”数据库实例的配置中更改了以下内容。

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

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

我还更改了查询的执行。

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

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

现在我收到以下错误

PDOException [0]:找不到驱动程序

我不确定这是否是进展,但有更多信息可以分享。

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,
    '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

///////////// 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-09-10 01:36:43

我的第一条评论是,您已将 Kohana 配置为使用 mysql 'type' => 'mysql',。现在尝试更新并回复我们。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文