Connection to PostgreSQL PHP THROUGH
In web applications, to authenticate to the
database system can use various interfaces such as CGI applications or programs
and server API. Apache Web Server can interact with database systems by using
modules such as php, jsp or CGI and can use to connect the client with the
server database. CGI programs, php or jsp scripts can contain user names and
passwords for autientikasi to the database server. In the chapter this post I
will discuss the connection to the PostgreSQL channeled through PHP.
PHP already has the complete functions to
interact with PostgreSQL; complete information about these functions can be
seen on the site http://www.php.net/manual/ref.pgsql.php.
This post will only be reviewed briefly about
how PHP related PostregSQL. An example of a simple PHP script to connect to
PostregSQL is as follows:
1 Connection To PostregSQL
Before you can interact with PostregSQL, first
of all you need to do is open a connection with PostregSQL. Each connection
represents by with a variable. In the example above is "dbkoneksi".
PHP can create multiple connections yan each with connections to PostregSQL.
Examples of this function are as follows:
Use PHP variables can be used to open the database, as follows:
The options in the pg_connect function displayed in Table 1
Table 1: Options function pg_connect
Table 1: Options function pg_connect
Opsi
Dbname = name of the database to be contacted
User = user name used to connect
Password = password used to connect
Host = host name of the server that provides PostregSQL
Hostaddr = IP address of the server that provides PostregSQL
Port = TCP port is opened server
User = user name used to connect
Password = password used to connect
Host = host name of the server that provides PostregSQL
Hostaddr = IP address of the server that provides PostregSQL
Port = TCP port is opened server
If the connection is done successfully then the function pg_connect will provide true value so that if the connection is been able to or will not be detected. The following is an example PHP script for detecting something connection.
2 Connection information to PostregSQL
After the connection it will be able to see the information of the connections that have been built. Information can be obtained by database name, host name and port that the server is used. The following PHP script can view after the connection occurs:
3 Termination Connection to PostregSQL
Pg_close function () is a PHP function that is used to decide PostregSQL to function, as the following example:

No comments:
Post a Comment