PHP

PHP is a server-side scripting language.

It was mainly developed for the web but can also be used as a general-purpose programming language.

PHP works well with MySQL and can be used in combination with HTML to create a webapp that connects to a database.

Working:

  1. web browser sends HTTP requests and receives HTTP responses

  2. PHP script (on the server-side) connects to DBMS and uses query results to produce its output

  3. web server calls the PHP script and incorporates its output into the response

  4. web browser renders the HTML document from the response

Executing SQL from PHP:

  1. connect to server (mysql_connect)

  2. select the database (mysql_select_db)

  3. run query

  4. retrieve row of results (mysql_fetch_array)

  5. retrieve attributes (foreach)

A typical web-app will have the following components:

  • Login page:

    Collect credentials and pass them to setup page via POST

  • Setup page:

    • Check credentials

    • Initialize session and session variables

    • Redirect to welcome page

  • Application pages:

    Call session_start(), authenticate the session, and use/ update session variables, as needed

  • Logout page:

    • Calls session_destroy()

    • Redirects to “goodbye” page

Last updated