php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18913 pg_pconnect opens a new connection even when and old one is available
Submitted: 2002-08-15 03:30 UTC Modified: 2002-08-15 04:54 UTC
From: jc at mega-bucks dot co dot jp Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.2.2 OS: Red Hat Linux 7.2
Private report: No CVE-ID: None
 [2002-08-15 03:30 UTC] jc at mega-bucks dot co dot jp
It seems that I cannot use pg_pconnect to connect to more than on database at a time?

The following code fails with this error:

Warning: pg_pconnect() cannot create new link. Too many open links (1) in /www/htdocs/jc/t2.php on line 26

Warning: pg_exec(): supplied argument is not a valid PostgreSQL link resource in /www/htdocs/jc/t2.php on line 27
CONNECTION: could not execute query2 (select now())

<?php

$sql = "select now()";

//uncommenting one of the following lines will make the code work

$res1 = sql_query($sql);
$res2 = sql_query2($sql);

$dat = pg_fetch_object($res1); //or res2 as the case maybe

echo $dat->now;

function sql_query($sql) {
  
  $conn = pg_pconnect("dbname=JC user=postgres");
  $res  = pg_exec($conn, $sql);
  
  if (!$res) {
    echo "CONNECTION: could not execute query ($sql)<br>";
    die;
  }
  else {
    return $res;
  }
}

function sql_query2($sql) {
  
  $conn = pg_pconnect("dbname=sessions user=postgres");
  $res  = pg_exec($conn, $sql);
  
  if (!$res) {
    echo "CONNECTION: could not execute query2 ($sql)<br>";
    die;
  }
  else {
    return $res;
  }
}
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-15 04:37 UTC] sander@php.net
There's a ini-directive that limits the maximum number of persistant connections. See phpinfo().
 [2002-08-15 04:54 UTC] jc at mega-bucks dot co dot jp
My mistake, the max had been set to 1. Thanks for the friendly reminder!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC