Search code examples
phpcodeigniterpostgresqlpostgresql-9.1appfog

CodeIgniter website with PostgreSql database in APPFOG


I am running a website in Codeigniter framework. I am using postgresql. I went through APPFOG documentation. But it is not clear to me how I configure postgres database . Where do I host the database? How do I make database updates?


Solution

  • Database.php inside application/config, replace the lines,

    <pre>
    $db['default']['hostname'] = '<ur hostname>';
    $db['default']['username'] = '<ur db username>';
    $db['default']['password'] = '<ur db password>';
    $db['default']['database'] = '<ur db name>';
    </pre>
    

    with

    <pre>
    $VCAP_SERVICES = getenv("VCAP_SERVICES");
    $VCAP_SERVICES_json = json_decode($VCAP_SERVICES, true);
    $VCAP_SERVICES_postgresql_config = $VCAP_SERVICES_json["postgresql-9.1"][0]["credentials"];
    $db['default']['hostname'] = $VCAP_SERVICES_postgresql_config['hostname'];
    $db['default']['username'] = $VCAP_SERVICES_postgresql_config['user'];
    $db['default']['password'] = $VCAP_SERVICES_postgresql_config['password'];
    $db['default']['database'] = $VCAP_SERVICES_postgresql_config['name'];
    </pre>
    

    That would take care of database connectivity. for making updates use af tunnel.