View Single Post
Old 15. Jun 2009, 11:47 PM   #8 (permalink)
George
Progradminstrateditor
 
George's Avatar
 
Join Date: Mar 2008
Location: Frankfurt, GER
Posts: 2,300
Default

Hi w,

the term "web server" is ambiguous. On the one side it stands for the whole sever computer running all necessary software to power your website. On the other side the term is also used for that piece of software running on that computer that is responsible for interpreting your html code and sending the pages to the requesting browser.

Web server software (like the popular Apache) can usually load addl. modules that enable it to do more than interpret html code, e.g. loading a PHP module so that also PHP code is interpreted and converted to web pages sent back to the requesting browser. You usually configure the web server in a way that it loads the appropriate addl. modules (other than html) based on the file extension. Files ending with .php are also interpreted with the PHP module. A proper HTML/PHP file that has an unknow file extension will not be interpreted accordingly.

Usually web developers progress in three steps:
1) Markup language (HTML)
2) Programming language (e.g. PHP)
3) Database Server

The term "database server" already points out that you need another piece of software running on your web server computer: the database server software. The most popular is a MySQL server.

A database server allows you to store and access data in a database during the interpretation of your website files. However, HTML cannot do that. You need a programming language that has built in routines and capabilities to connect to a database server and talk to it. That would be PHP in our example.

But in order to talk to a database server you need to use a language that the database server understands. That would be MySQL in our case.

So once you have a webserver with PHP and a database server running, here are some very basic examples what you can do with it.

Simple HTML
HTML Code:
<html>
  <head>
    <title>My HTML Page</title>
  </head>
  <body>
    <h1>Hello World</h1>
  </body>
</html>
Simple PHP/MySQL
PHP Code:
<html>
  <head>
    <title>My PHP Page</title>
  </head>
  <body>
    <h1><?php echo "Hello World";?></h1>
  </body>
</html>
Simple Database Access:
PHP Code:
<html>
  <head>
    <title>My PHP-MySQL Page</title>
  </head>
  <body>
<?php
  
// Establish a connection to the MySQL database
  
$connection mysql_connect("localhost""myusername""mypassword");
  
// Use the address database
  
mysql_select_db("addresses"$connection);

  
// Run a query through the connection
  
$result mysql_query("SELECT id, surname, 
        firstname FROM contacts"
$connection);

  
// Fetch each row of the results into an array $row
  
while ($row mysql_fetch_array($result))
  {
     echo 
"ID:\t{$row["id"]}\n";
     echo 
"Surname\t{$row["surname"]}\n";
     echo 
"First name:\t{$row["firstname"]}\n\n";   
  }
?>
</body>
</html>
This will give you a basic idea of how it works. One thing is important of course: in the upper example it is assumed that the database "addresses" with its table "contacts" exists.

You need to create this database before you can access it. There is a popular free program that you can used to create databases in your database. It is called phpMyAdmin and is a web application itself.

The easiest way to get started with a local web server on your computer is to download on of the free packages that include everything you need already. I am using XAMPP, others suggest WAMPSERVER. Once you install such a package you have HTML, PHP, MySQL Server and phpMyAdmin ready to go.

In the example of Xampp you do this:
1) Install Xampp
2) Start the Xampp Control Panel
3) In the Control Panel start the Web Server and the Database Server
4) Open your browser and go to http://localhost

Ok, so much for a very quick and simple introduction. I guess you can take it from there.

If you need further assistance just post it here.
__________________
Best regards, George
George is offline