Database Connectivity with the Internet

Internet applications have connected to online databases for many years and it is becoming more and more common for sites to connect to databases too to serve their pages through content management systems. As a result database connectivity is an important part of designing any Internet based system.

In my experience using MySQL and PHP Internet technologies it is necessary for a PHP script to access data that may or may not be located on the same server as the script itself. As a result, the first information that the PHP script needs to establish a connection to the database is the location of the server where the database is situated (e.g. IP address or name) and access credentials (username and password). This information is usually stored in a configuration file that, for security purposes to prevent illegal database access, is location in the non-Internet accessible part of the file structure.

Given that this database configuration information is correct and the access credentials have an appropriate level of access to the data required, PHP can use the mysql_connect command to connect to the database ($db = mysql_connect($hostname,$username,$password);). The permissions for the script to interact with the data are dictated by the database itself and in terms of an Internet user browsing a web site this would simply allow read permissions on database content. However, the Internet site manager would have permission to alter content (and therefore have write permissions) from the same system.

Once connected, the PHP script can query data from the MySQL data structure using predefined variables in order to populate pages for user requests, perform calculations and gather user information as required.