连接postgresql和codeigniter [英] connecting postgresql and codeigniter
问题描述
我是新的使用postgresql和我一直使用Codeigniter一年。
我有一个小的postgresql数据库,我想从Codeigniter调用它。 / p>
在我的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'=>'' b $ b'pconnect'=> FALSE,
'db_debug'=> TRUE,
'cache_on'=> FALSE,
'cachedir'=> $ b'char_set'=>'utf8',
'dbcollat'=>'utf8_general_ci',
'swap_pre'=>'',
'encrypt'=> FALSE ,
'compress'=> FALSE,
'stricton'=> FALSE,
'failover'=> array(),
'save_queries'=>
//'port'=>'5432'
);
在控制器中我有这个功能:
public function dbtest(){
$ this-> load-> database
$ feeds = $ this-> db-> get('vts_feeds');
echo $ feeds; die();
}
我得到的结果是:
遇到错误
您尚未选择要连接的数据库类型。
为什么不工作?
尝试设置
dbdriver - 数据库类型。即:mysql,postgres,odbc等。必须以小写形式指定
。
更多信息: https://ellislab.com/codeigniter/user-guide/database/configuration.html
EDIT:在postgres
$中为 PDO
b $ b
$ db ['default'] ['hostname'] ='pgsql:host = localhost; dbname = yourdb'; // set host
$ db ['default'] ['username'] ='您的用户名'; // set username
$ db ['default'] ['password'] ='您的密码'; // set password
$ db ['default'] ['database'] ='您的数据库'; // set databse
$ db ['default'] ['dbdriver'] ='pdo'; // set driver here
I'm new using postgresql and I've been using Codeigniter for a year.
I have a small postgresql database and I wanna call it from Codeigniter.
In my database.php file I have this setup:
$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'
);
In a controller I have this function:
public function dbtest(){
$this->load->database();
$feeds = $this->db->get('vts_feeds');
echo $feeds;die();
}
The result I'm getting is:
An Error Was Encountered
You have not selected a database type to connect to.
Why is it not working?
Try to set,
dbdriver - The database type. ie: mysql, postgres, odbc, etc. Must be specified in lower case.
More Info: https://ellislab.com/codeigniter/user-guide/database/configuration.html
EDIT: Try this config for PDO
in postgres
$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
这篇关于连接postgresql和codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!