Web Databases

Websites provide information to users. To read more about web technology, checkout this link. Web pages can be authored using HTML, XML, PHP, Javascript, etc. Information displayed on a webpage may come from a database. There are ways to interface with a database, such as using PHP Database Interface. The following are the steps to connect to a database and store or retrieve information:
  1. Connect to the computer where database server is running using a user ID and password
  2. Select the database to access (Note that a database system may contain multiple databases)
  3. Prepare the query in SQL (See Database Technology link for more information)
  4. Execute the query and obtain the results into a memory location
  5. Process the results
  6. Close the database connection
Here is an example: <?php mysql_connect('mysql.cstrends.com:1210','root','password'); //Step 1 /* Change the above line depending on your database server address, port number, user name and password*/ @mysql_select_db('dbName') or die("Unable to select database"); //Step 2 $query="SELECT * FROM MYTABLE;"; //Step 3 $results = mysql_query($query); //Step 4 $norows = mysql_numrows($results); //Step 5 for ($i = 0; $i < $norows; $i++) { echo mysql_result($results, $i, 'slno') . "<br/>\n"; } mysql_close(); //Step 6 ?> References
  1. PHP/MySQL Introduction from W3Schools
  2. PHP/MySQL Tutorial
  3. PHP/MySQL functions
  4. PHP Documentation
  5. MySQL Documentation

You may share this article on Facebook.