Database connection not closed (ARCH7084)
Ce contenu n’est pas encore disponible dans votre langue.
Key php.performance.db-connection-not-closed · Severity error · Category performance
A database connection or cursor that is opened but never released exhausts the pool and leaks connections. Close it or return it to the pool when done.
Incorrect
Section titled “Incorrect”<?phpfunction rowCount(): int{ $conn = pg_connect('host=db dbname=app'); $res = pg_query($conn, 'SELECT count(*) FROM users'); return (int) pg_fetch_result($res, 0, 0);}Correct
Section titled “Correct”<?phpfunction rowCount(): int{ $conn = pg_connect('host=db dbname=app'); $res = pg_query($conn, 'SELECT count(*) FROM users'); $count = (int) pg_fetch_result($res, 0, 0); pg_close($conn); return $count;}Close connections and cursors with a call like pg_close() as soon as work finishes, returning them to the pool.