I recently did a re-install of PostgreSQL and php4 on Debian, which has
broken some development code here. None of the actual code has changed in
days, which I can verify against the CVS tree, so I know it's one of two
things:
a) botched server config
b) the code wasn't as robust as it should have been in the first place.
What I have is a class (db_postgres) which we use for all DB access within
the project. The functions relative to what are breaking are as follows:
class db_postgres {
var $db_name = "ourdb";
var $db_user = "ouruserB";
var $db_conn;
// CORE FUNCTIONS
function get_connection() {
$this->db_conn = pg_connect("dbname=$this->db_name ".
"user=$this->db_user");
if ($this->db_conn == FALSE) {
echo "Internal warning: Db connection not established.\n";
}
}
function execute_sql($sql) {
$result = pg_exec($this->db_conn, $sql);
if ($result == NULL) {
echo "Error executing following SQL:<hr><pre>$sql</pre>\n";
}
return $result;
}
function get_rs($sql) {
// Returns an array of hashes
$this->get_connection();
$result = $this->execute_sql($sql);
if ($result == NULL)
return array();
$num = pg_numrows($result);
$result_set = array();
for($i = 0; $i < $num; $i++)
array_push($result_set, pg_fetch_object($result, $row++));
return $result_set;
}
[snip]
}
The following main php page (ommiting includes) works:
$db = new db_postgres;
$result = $db->get_rs("select * from vendor");
$result = $db->get_rs("select * from vendor");
However,
$db = new db_postgres;
$result = $db->get_rs("select * from vendor");
$db = new db_postgres;
$result = $db->get_rs("select * from vendor");
Will break on the second calls ot get_rs(). Yes, I -could- be passing
around the db handles, or passing around already instantiated class
objects, but this gets a bit messy. Plus, everything was working dandy
with making two $db objects within a single page... which is why this
bothers me.
The actual PHP error upon the second call is:
"Warning: 1 is not a valid PostgreSQL link resource in ... [snip]"
Suggestions?
Justin Buist
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]