Welcome Guest, Not a member yet? Register   Sign In
connecting to postgresql with pg_pconnect()
#1

(This post was last modified: 04-07-2020, 01:13 PM by richb201.)

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
Reply
#2

@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 ).
Reply
#3

(This post was last modified: 04-07-2020, 09:48 PM by richb201.)

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
Reply
#4

@richb201,

Documentation for multiple database connections ( https://codeigniter.com/userguide3/datab...-databases ).
Reply
#5

thank you
proof that an old dog can learn new tricks
Reply
#6

(This post was last modified: 04-10-2020, 10:55 AM by richb201.)

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
Reply
#7

(This post was last modified: 05-30-2020, 09:27 AM by richb201.)

(04-08-2020, 10:17 AM)php_rocs Wrote: @richb201,

Documentation for multiple database connections ( https://codeigniter.com/userguide3/datab...-databases ).
 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
Reply
#8

@richb201,

Is the other application on the same server as your current application? If not you might need to check your PHP.ini to make sure that the postgres plugin is turned on.
Reply
#9

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
Reply
#10

@richb201,

Yes, you are correct pg_connect() is not a CI function. Check the AWS forums or see if you can search the documentation. There has got to be a way for you to see your container's PHP.ini configuration.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB