An PgSql\Connection instance. When connection is null , the default connection is used. The default connection is the last connection made by pg_connect() or pg_pconnect() .
connection
null
As of PHP 8.1.0, using the default connection is deprecated.
示例 #1 pg_close() 示例
<?php $dbconn = pg_connect ( "host=localhost port=5432 dbname=mary" ) or die( "Could not connect" ); echo "Connected successfully" ; pg_close ( $dbconn ); ?>
以上示例会输出:
Connected successfully
This function closes the current database connection specified by a handle returned from a pg_connect() call. <?php $pgsql_conn = pg_connect ( "dbname=mark host=localhost" ); if ( $pgsql_conn ) { print "Successfully connected to: " . pg_host ( $pgsql_conn ) . "<br/>\n" ; } else { print pg_last_error ( $pgsql_conn ); exit; } // Do database stuff here. if(! pg_close ( $pgsql_conn )) { print "Failed to close connection to " . pg_host ( $pgsql_conn ) . ": " . pg_last_error ( $pgsql_conn ) . "<br/>\n" ; } else { print "Successfully disconnected from database" ; } ?> Of course you normally wouldn't print a message. Regards, --mark