在 OS X Snow Leopard 上使用 Kohana 3 数据库模块连接到 postgres 时出现问题
底部编辑/添加...
环境:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的第一条评论是,您已将 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.