我正在使用与codeigniter的Postgresql数据库连接。我是postgresql的新手。该网站打开。但我无法登录或从数据库中获取任何值。
我将上传配置文件的代码以及database.php文件。 的的config.php
// Keep as it is for same if MySQL server is running on same server
define("DBHOSTNAME",'ip_address');
// Add your database name here
define("DBNAME",'db_name'); // Here the database name is 'dummy_myecommerce'
// Add your database user name here
define("DBUSER",'username'); // Here the username is 'dummy_website'
// Add your database password here
define("DBPWD",'password');
现在我将上传 database.php 文件:
$db['default']['hostname'] = 'ip_address';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'db_name';
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = 'pre_';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = 5432;
如果还有其他要求,请告诉我。感谢
答案 0 :(得分:0)
某些数据库驱动程序(如PDO,PostgreSQL,Oracle,ODBC)可能需要提供完整的DSN字符串。如果是这种情况,您应该使用'dsn'配置设置,就好像您正在使用驱动程序的底层本机PHP扩展,如下所示:
// PDO $ db ['默认'] [' dsn'] =' pgsql:host = localhost; port = 5432; dbname = database_name&#39 ;;
有用的链接 - http://www.codeigniter.com/user_guide/database/configuration.html
答案 1 :(得分:0)
Try this as well
$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