Hey all, I'm having difficulty with some database connection stuff.
A have a dbconnection class which defines a $connection variable holding the info for a PostgreSQL connection ($connection = pg_pconnect(blah)). I want to run a query using a different class, but I need to use the $connection variable to do so (pg_query("$connection, query")). I've tried different ways of doing this, like making the $connection variable public (so that other classes can use it), or extending the dbconnection class and using parent::$connection scope variables to access it, but it always seems to return the error, "Warning: pg_last_error(): supplied argument is not a valid PostgreSQL link resource", which is a nice way to tell you that you've messed up some place.
Procedurally, the code looks like this:
if ($connection = pg_pconnect("dbname=$dbname user=$username password=$password"))
{
print 'Success!';
} else {
die('Failure!');
}
if($query = pg_query($connection, "INSERT INTO shouts VALUES ('mijokijo', 'This thing works')"))
{
print $query;
} else {
die("Failed query" . pg_last_error());
}
This works perfectly, so I know it has to do with the way I am handling the database connection. How should I handle this? I was looking at sessions and thinking that they might do the trick, but I'm not sure how to use them for this sort of scenario.