connecting to postgresql with pg_pconnect() |
I need to connect my app with a remote Postgresql database. My app is running on the web and each user has her own copy. Is there any functionality in Codeigniter to use postgresql? If I connect with pg_pconnect() do I do this once and have all the tasks share the handle or can each task do this and keep its own copy of the handle?
proof that an old dog can learn new tricks
@richb201,
What version of CI are you using? Assuming you are using CI 3.1.x here is the link ( https://codeigniter.com/userguide3/datab...figuration ).
Thanks php_rocs. I am using 3.1. I use this structure for a local copy of mySQL. Can I have more than one database connected? I am using postgres to hold images because Jaspersoft can use it and images can be really large in postrgres. I know it is not a good idea to keep the actual image in a bytea, but if i don't, I will have trouble with Jaspersoft server.
So I can assume that I don't need to play with opening a connection and CI will do it for me? How about re-entrancy? Can I assume that is not a problem?
proof that an old dog can learn new tricks
@richb201,
Documentation for multiple database connections ( https://codeigniter.com/userguide3/datab...-databases ).
So now I want to add access to a remotely hosted copy of Postgres. But I don't want to redo the working mySQL functions. So I think I can create the $dsn to point at the Postgresql database:
This is the string I use to connect to psql: psql --host=imagesdatabase.cwymdn16cxes.us-east-1.rds.amazonaws.com --port=5432 --username=richb201 --password --dbname=postgres Can I use $dsn2='--host=imagesdatabase.cwymdn16cxes.us-east-1.rds.amazonaws.com --port=5432 --username=richb201 --password=xyz --dbname=postgres' Or is there some other syntax that I need to use? And then to open it and assign the $DBPostgres=$this->load->database($dsn2, TRUE); And when I want to access the Postgres I will use $DBPostgres->query();
proof that an old dog can learn new tricks
(04-08-2020, 10:17 AM)php_rocs Wrote: @richb201,I have two databases defined in my database.php. The first is called default and is my local mySQL database. The second is called postgres and connects to remote copy of postgresql. I then run this: $DB1 = $this->load->database('default', TRUE); $DB2 = $this->load->database('postgres', TRUE); $DB1 seems to work. $DB2 results in an error: "call to undefined function pg_connect()". The DSN for postgres is 'dsn' => 'jdbc:postgresql://imagesdatabase.cwymdn16cxes.us-east-1.rds.amazonaws.com:5432/postgres' This dsn works fine in another application I am using to connect to the postgresql database. Do I need to somehow load the postgres driver? BTW, my autoload.php contains: $autoload['drivers'] = array(); Does this means that IO have not loaded the pg driver?
proof that an old dog can learn new tricks
hey Rocs! It is all running on my local PC at this time, except the RDS postgresql which is running on an AWS server somewhere. I am just not sure how to see the php.ini that is running inside the container. pg_connect() is not a CI function I am assuming.
proof that an old dog can learn new tricks
|
Welcome Guest, Not a member yet? Register Sign In |