【问题标题】:Codeigniter/Postgresql: Site works but cannot fetch data from dbCodeigniter/Postgresql:站点工作但无法从数据库中获取数据
【发布时间】:2016-07-19 10:13:35
【问题描述】:

我正在使用带有 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;

如果还有什么需要,请告诉我。谢谢

【问题讨论】:

  • 在您的应用程序/配置目录中查找名为 autoload.php 的文件,您是否已自动加载数据库库? $autoload['libraries'] = array("database",....);
  • 谢谢回复,我去看看。

标签: php postgresql codeigniter


【解决方案1】:

某些数据库驱动程序(例如 PDO、PostgreSQL、Oracle、ODBC)可能需要提供完整的 DSN 字符串。如果是这种情况,您应该使用“dsn”配置设置,就好像您使用的是驱动程序的底层原生 PHP 扩展一样,如下所示:

// PDO $db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';

有用的链接 - http://www.codeigniter.com/user_guide/database/configuration.html

【讨论】:

  • 首先尝试使用本地脚本连接到 postgre,以确保详细信息正确
  • 从这个链接tutorialspoint.com/postgresql/postgresql_php.htm使用corephp的本地脚本似乎工作
  • 尝试 $db['default']['dbdriver'] = 'pdo'; //在此处设置驱动程序。检查我上面的其他答案。
  • 您好,抱歉耽搁了,我设法解决了,数据库中有问题
【解决方案2】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    相关资源
    最近更新 更多