Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: 12252 Week 8 – Review Reference:

Similar presentations


Presentation on theme: "ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: 12252 Week 8 – Review Reference:"— Presentation transcript:

1 ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: 12252 Email: x.gao@mdx.ac.ukx.gao@mdx.ac.uk Week 8 – Review Reference: http://www.w3schools.com/phphttp://www.w3schools.com/php

2 Webpage Basic Architecture From Jay Greenspan and Brad Bulger “MySQL/PHP Database Applications”, M&T Books, New York, 2001. At the most basic level, the Web works off of a client/server architecture. That means that both a central server and a client application are responsible for some amount of processing.

3 Web Server and Client Essentially, a Web server is a software application that listens for client connections on a specific network port. When a connection is made, the Web server then waits for a request from the client application. The client is usually a Web browser, but it could also be a Web site indexing utility, or perhaps an interactive telnet session. The resource request, usually a request to send the contents of a file stored on the server, is always phrased in some version of the Hypertext Transfer Protocol (HTTP).

4 You are here! You can’t see!

5 Why PHP Fast – written in C but simpler. Easy – Syntax is believed to be superior to ASP and JSP. Easy to learn than Perl – a shell C-like language. Cross-platform Accesses everything – IMAP ( Internet Message Access Protocol ) Mail server, Oracle, Informix, DB2, XML parser, WDDX (Web Distributed Data eXchange ) function, etc.. Constantly being improved – part of open source development. Fully supported all over the world. FREE.

6 Why MySQL – technical features Written in C and C++. Works on many different platforms. Fully multi-threaded using kernel threads -- can easily use multiple CPUs if available. A very fast thread-based memory allocation system.

7 Basic UNIX commands Start ‘Command Prompt’ – or type ‘cmd’ from ‘search window’ cd c:\xampp – change to directory ‘c:\xampp’ dir – list all the contents of current folder

8 Start Xampp 1) In the folder c:\xampp, double click ‘xampp- control.exe’ at 2) Click ‘Start’ for both ‘Apache’ and ‘MySQL’.

9 Start MySQL 1) Start ‘Command Prompt’ 2) cd c:\xampp\mysql\bin 3) mysql (or ‘mysql –u root’ (no password for now))

10 MySQL mysql> show databases; (list databases that have been in the system.)

11 MySQL (2) mysql> use test; (use database ‘test’) Query OK, 1 row affected (0.00 sec) mysql> show tables; mysql> CREATE TABLE y2k (date DATE, -> date_time DATETIME, -> time_stamp TIMESTAMP); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO y2k VALUES -> ("1998-12-31","1998-12-31 23:59:59",19981231235959), -> ("1999-01-01","1999-01-01 00:00:00",19990101000000), -> ("1999-09-09","1999-09-09 23:59:59",19990909235959); Query OK, 13 rows affected (0.01 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql>

12 MySQL (3) mysql> SLECT * from y2k;

13 Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with <?php // PHP code goes here ?> The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code. Example: "Hello World!".

14 1. First web page //comments <?php echo "My first PHP script!"; ?>

15 Connection with MySQL <?php $host= "localhost "; $user = "root "; $passwd = " “; $database = “test”; $connect = mysql_connect($host, $user, $passwd); $DBSelect = mysql_select_db($database, $connect); If (!$connect || !$DBSelect) { $Status = "Not connected"; /*. mysql_error();*/ die('Could not connect: '. mysql_error()); } else { $Status = "Connected"; echo 'Connected successfully'; } ?>

16 Get data from MySQL <?php $host= "localhost"; $user = "root "; $passwd = " “; $database = “test”; $tbl_name = “pet” mysql_connect($host, $user, $passwd) or die("cannot connect server "); mysql_select_db($database) or die("cannot select DB"); $result=mysql_query("SELECT * FROM pet"); while($rows = mysql_fetch_array($result)) { echo $rows['name']. "\t“. $rows['species']. " "; } mysql_close(); //close database ?>

17 Insert data to MySQL <?php $host= "localhost"; $user = "root "; $passwd = " “; $database = “test”; $tbl_name = “pet” mysql_connect ($host, $user, $passwd) or die("cannot connect server "); mysql_select_db("$database") or die("cannot select DB"); $sql = “Insert Into $tbl_name (Name, species) VALUES (‘Polo', ‘Cat')"; $result = mysql_query ($sql); if($result) { echo "Successful"; echo " "; } mysql_close(); //close database ?>

18 Together – insert & retrieval <?php $host= "localhost"; $user = "root "; $passwd = " “; $database = “test”; $tbl_name = “pet” mysql_connect ($host, $user, $passwd) or die("cannot connect server "); mysql_select_db("$database") or die("cannot select DB"); $sql=“Insert Into $tbl_name (Name, species) VALUES (‘Polo', ‘Cat')"; $result=mysql_query($sql); $result = mysql_query("SELECT * FROM $tbl_name"); while($rows = mysql_fetch_array($result)) { echo $rows[ ' name ' ]. "\t“. $rows[ ' species ' ]. " "; } mysql_close(); //close database ?>

19 ITX2000 Course work: CW1(50% marks) Task Installing XAMPP software in a USB stick creating a personal web page to describe your birthplace, including photos to highlight the landmarks of this country/city/town/village This web page allows a feedback form, so that viewers can send their comments no your webpage or to make recommendations, i.e., a guest book. a. Use Apache HTTP server b. Use Mysql to provide the comments database c. Create a database/table to retain/save users’ comments. d. Use PHP language to realise client- server communication


Download ppt "ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: 12252 Week 8 – Review Reference:"

Similar presentations


Ads by Google