PHP Function Pg_DBname - Functions That Work With PostgreSQL From Your PHP Scripts
php function pg_dbname is one of many powerful functions in the PHP language. This article will introduce some of the important ones that you need to work with PostgreSQL databases from your PHP scripts.
Most of these functions accept a connection as the first optional parameter. In case it is not provided, a default database connection is used. The next parameter is a SQL statement or a query to execute. Then a resultset is returned if the query is successful. If not, a failure message is reported.
A few of these functions also allow you to gather extra information from the result set such as the line number in the PostgreSQL source code that an error was detected. This information can be useful when troubleshooting errors.
Another helpful function is pg_fieldname(), which returns the field name as given in the SELECT statement. This information can also be useful to help you determine the cause of a problem with your queries.
You can find a lot more useful functions in the PostgreSQL library that is part of the PEAR package. PEAR provides a database abstraction interface, which will make it easier to use the PostgreSQL library from your scripts than trying to call the database's native functions directly. Using this interface will make it easier to migrate your projects to different databases as well.
A few other important routines to know are pg_result_status(), which reports the status of the current query, and pg_send_query_params(), which submits a command and separate parameters to the server without waiting for the results. Both of these routines are very similar to the method function in object-oriented programming languages such as Java and C++.