gpt4 book ai didi

php - 连接 postgresql 和 codeigniter

转载 作者:可可西里 更新时间:2023-11-01 13:38:31 25 4
gpt4 key购买 nike

我是 postgresql 的新手,我已经使用 Codeigniter 一年了。

我有一个小型 postgresql 数据库,我想从 Codeigniter 调用它。

在我的 database.php 文件中我有这样的设置:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn' => 'pgsql:host=localhost;port=5432;dbname=test;user=postgres;password=aPass',
// 'dsn' => '',
'hostname' => 'localhost',
'username' => 'postgres',
'password' => 'aPass',
'database' => 'test',
'dbdriver' => '',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
// 'port' => '5432'
);

在 Controller 中我有这个功能:

public function dbtest(){

$this->load->database();

$feeds = $this->db->get('vts_feeds');
echo $feeds;die();
}

我得到的结果是:

An Error Was Encountered
You have not selected a database type to connect to.

为什么它不起作用?

最佳答案

尝试设置,

dbdriver - The database type. ie: mysql, postgres, odbc, etc. Must be specified in lower case.

更多信息:https://www.codeigniter.com/user_guide/database/configuration.html

编辑:在 postgres 中为 PDO 尝试此配置

$db['default']['hostname'] = 'pgsql:host=localhost;dbname=yourdb'; //set host
$db['default']['username'] = 'your username'; //set username
$db['default']['password'] = 'your password'; //set password
$db['default']['database'] = 'your database'; //set databse
$db['default']['dbdriver'] = 'pdo'; //set driver here

关于php - 连接 postgresql 和 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29630851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com