底部的编辑/添加...
环境:
Mac OS X 10.6 雪豹
PHP 5.3
Kohana 3.0.4
当我尝试在 localhost 上配置和使用与 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 所尝试的不同。
巴特
//////////// 编辑一个 /////////////
根据马特的评论,我在“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]:找不到驱动程序
我不确定这是否是进步,但可以分享更多信息。