CodeIgniter Forums

Full Version: organization of crud for postgrsql
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using an AWS managed version of Postgrsql. I have also found a document called "Postgrsql CRUD operations in PHP" https://www.idiotinside.com/2015/07/25/p...ns-in-php/. The reason for using Postgrsql is that it can handle a blob larger than 1M. The reason for using the AWS RDS rather than postgres in a container to keep the size down. I have a bunch of files to store in it such as .xls, .pdf, .ppt. My question is regarding the organization of Codeigniter files in the project. I of course have a controller that runs the UI. I'd like to be able to call the  CRUD functions and I'd like to keep them in a separate module from the controller. Where should I put them so that I can call the functions directly from the controller?
OK. I have created a table in AWS RDS postgres and I have modified my database.php. Here is the setup in database.php for the postgres:
$db['postgres'] = array(
    'dsn' => '',
    'hostname' => 'postgresql://imagesdatabase.cwymdn16cxes.us-east-1.rds.amazonaws.com',
    'username' => 'richb201',
    'password' => 'xxx',
    'database' => 'images',
    'dbdriver' => 'postgre',  //ok
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    '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
);

Before I break out the champagne Smile, how can I test that I can connect to the RDS postgres from CI? I also have a local mySQL dbase which is the default ( $dn['default']= array(...) When I $this->load->database(), I don't get an error. Does this mean my connection to postgres worked? I am using Jaspersoft Studio and with it I can connect to the RDS Postgres fine as the "test link" in Jaspersoft Studio shows.

I modified the dsn to be: dbc:postgresql://imagesdatabase.cwymdn16cxes.us-east-1.rds.amazonaws.com:5432/postgres as per the note in the CI manual.
Well I decided to go back and hit the manual again. This is what the manual says:
Connecting to your Database
You can connect to your database by adding this line of code in any function where it is needed, or in your class constructor to make the database available globally in that class.

$db = \Config\Database::connect();
If the above function does not contain any information in the first parameter it will connect to the default group specified in your database config file. For most people, this is the preferred method of use.

In my case I am using $db=\Config\Database::connect('postgres');
I am getting an error when I call this: "Class Config\Database' not found" Does anyone know what this means?
I also see a note in the manual that says: "If the above function does not contain any information in the first parameter it will connect to the default group specified in your database config file. For most people, this is the preferred method of use.". What first parameter are they talking about? I don't want to use default  since that is my local mySQL. 
What does "not contain any information in the first parameter" mean, in this case?