1 / 74

Chapter 1. Laboratory PHP and MySQL CRASH COURSE

Chapter 1. Laboratory PHP and MySQL CRASH COURSE. Overview:. Discussion of the basic architecture of a web application. Discussion of the relevance of using MySQL and PHP in a web application. Basic Architecture of a Web Application. Additional considerations in the architecture Client

lala
Download Presentation

Chapter 1. Laboratory PHP and MySQL CRASH COURSE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1. LaboratoryPHP and MySQL CRASH COURSE

  2. Overview: • Discussion of the basic architecture of a web application. • Discussion of the relevance of using MySQL and PHP in a web application.

  3. Basic Architecture of a Web Application Additional considerations in the architecture • Client • Server • Operating System

  4. TASKS OF THE WEB SERVER • The Web server has what seems to be a fairly straightforward job. It sits there, running on top of your operating system, listening for requests that somebody on the Web might make, responding to those requests, and serving out the appropriate Web pages. In reality, it is a bit more complicated than that, and because of the 24/7 nature of the Web, the stability of the Web server is a major issue. There are many Web servers out there, but two dominate the market. These are Apache and Microsoft’s Internet Information Server (IIS).

  5. TASKS OF THE MIDDLEWARE • The middleware work closely with the Web server to interpret the requests made from the World Wide Web, process these requests, interact with other programs on the server to fulfill the requests, and then indicate to the Web server exactly what to serve to the client’s browser.

  6. RELATIONAL DATABASES • Relational database management systems (RDBMSes) provide a great way to store and access complex information. They have been around for quite a while. In fact, they predate the Web, Linux, and Windows, so it should be no surprise that there are many RDBMSes to choose from. All the major databases make use of the Structured Query Language (SQL).

  7. Tools to check before running PHP application (with MySQL). In PHP you should have the following software: 1. PHP code editor (IDE). 2. PHP compiler/interpreter. 3. Web Server While in MySQL: 1. Driver 2. Server 3. The MySQL Database Manager

  8. The PHP script • Now’s the time to move to the text editor. In the course of configuring your Web server, you need to let it know which files should be handed off to PHP so the engine can interpret the page. Most often, these files have a .php extension, though it is possible to have PHP interpret anything, including .html files. These scripts live inside the folder designated to hold Web pages. For Apache, this is usually /htdocs.

  9. BASIC SYNTAX One neat thing about PHP is that it lets you move between straight HTML and commands that are part of the PHP programming language. It works like this: The sections of your script between the opening tag (<?php) and the closing tag (?>) are interpreted by the PHP engine, and portions not within these tags are treated as plain HTML. Check out the following PHP page.

  10. Code Overview <?phpecho “Hi, mom. “;$var = date(“H”);if ($var <= 11){echo “good morning”;}elseif ($var > 11 and $var < 18){echo “good afternoon”;}else{echo “good evening”;}?> <?php echo “Hi”; ?> mom.

  11. Connecting to the Database (PHP to MySQL) <?php mysql_connect(“localhost”,”nobody”,”ydobon”) or die(“<h3>could not connect toMySQL</h3>\n”); mysql_select_db(“guestbook”) or die(“<h3>could not select database ‘guestbook’</h3>\n”); ?>

  12. Working with PHP • Getting Started with PHP – variables • Data types • Operators • Control Structure • If statement • else statement • elseif statement • Switch statement • Iteration • while loop • for loop • do .. While loops • PHP’s built-in function • Writing organized and readable code

  13. Assigning Simple VariablesWithin a Script $a = “this is a string”; //this is a string $b = 4; //this is an integer $c = 4.837; //this is a floating-point number $d = “2”; //this is another string Typing is flexible, and PHP is pretty smart about handling changes in types. Fore example, given the code you just saw, the following would evaluate as you’d probably hope: $e = $b + $d; echo $e; answer: 6

  14. Another example: $a = 2; $b = “2 little piggies”; $c = $a + $b; answer: $c=4 $f = 2; //$f is an integer $g = 1.444; // $g is a double (floating-point) type $f = $f + $g; //$f is now a double type answer: 3.444

  15. PHP will also do type conversions when comparing two variables. This is a goodthing, because the most common values for a script, entries submitted from anHTML form, always come in as strings. Here’s an example: $a = ‘1.3’; if ($a == 1.3) { echo “‘$a’ is 1.3\n”; } else { echo “‘$a’ is not 1.3\n”; } answer: ‘1.3’ is 1.3

  16. If you need to make a strict comparison, where the types as well as the valuesmust match, you can use a triple equal sign (===) operator (or its inverse, !==). Thismost commonly arises when you need to distinguish between 0, NULL, FALSE, andan empty string, since in a normal comparison these will all be treated as equal. Thefollowing code demonstrates: $a = 0; if ($a === 0) { echo “‘$a’ is 0\n”; } else { echo “‘$a’ is not 0\n”; } if ($a === FALSE) { echo “‘$a’ is FALSE\n”; } else { echo “‘$a’ is not FALSE\n”; } The result: ‘0’ is 0 ‘0’ is not FALSE

  17. Delimiting strings $my_name = “Jay”; $phrase = “Hello, my name is $my_name”; echo $phrase;

  18. PHP TAG STYLES • SHORT STYLE <? … ?> • XML STYLE <?php … ?> • SCRIPT STYLE <script language = ‘php’> … </script> • ASP STYLE <% … %>

  19. PHP’s data type • PHP supports the following data types: 1. Integer – wholes numbers 2. Double – real numbers 3. String – string characters 4. Array – use for multiple storage of values 5. Object – use to store instances of classes

  20. PHP’s arithmetic operators

  21. PHP’s string operator

  22. PHP’s combined arithmetic operations

  23. PHP’s comparison operators

  24. PHP’s logical operators

  25. Control Structure if else

  26. Continued… elseif

  27. switch case

  28. ITERATION while loop

  29. for loop for example

  30. do..while loop example

  31. CSS Cascading Style Sheet

  32. INTRODUCTION TO CSS • What You Should Already Know Before you continue you should have a basic understanding of the HTML. What is CSS? • CSS stands for Cascading Style Sheet • Styles define how to display HTML elements • Styles were added to HTML 4.0 to solve a problem • External Style Sheets can save a lot of work • External Style Sheets are stored in CSS files

  33. Styles Solved a Big Problem • HTML was never intended to contain tags for formatting a document. • When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process. • In HTML 4.0, all formatting could be removed from the HTML document, and stored in a separate CSS file. • All browsers support CSS today.

  34. CSS Saves a Lot of Work! • CSS defines HOW HTML elements are to be displayed. • Styles are normally saved in external .css files. External style sheets enable you to change the appearance and layout of all the pages in a Web site, just by editing one single file!

  35. CSS Syntax • A CSS rule has two main parts: a selector, and one or more declarations: • The selector is normally the HTML element you want to style. • Each declaration consists of a property and a value. • The property is the style attribute you want to change. Each property has a value.

  36. CSS Example • CSS declarations always ends with a semicolon, and declaration groups are surrounded by curly brackets p {color:red;text-align:center;} • To make the CSS more readable, you can put one declaration on each line, like this: p{color:red;text-align:center;}

  37. CSS Comments • Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this:

  38. CSS Id and Class The id Selector • The id selector is used to specify a style for a single, unique element. • The id selector uses the id attribute of the HTML element, and is defined with a "#". • The style rule below will be applied to the element with id="para1":

  39. The class Selector • The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. • This allows you to set a particular style for any HTML elements with the same class. • The class selector uses the HTML class attribute, and is defined with a "." • In the example below, all HTML elements with class="center" will be center-aligned:

  40. You can also specify that only specific HTML elements should be affected by a class. • In the example below, all p elements with class="center" will be center-aligned:

  41. Three Ways to Insert CSS There are three ways of inserting a style sheet: • External style sheet • Internal style sheet • Inline style

  42. External Style Sheet • An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:

  43. An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:

  44. Internal Style Sheet • An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

  45. Inline Styles • An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly! • To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:

  46. Multiple Style Sheets • If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet.  • For example, an external style sheet has these properties for the h3 selector:

  47. And an internal style sheet has these properties for the h3 selector:

  48. If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:

  49. Multiple Styles Will Cascade into One Styles can be specified: • inside an HTML element • inside the head section of an HTML page • in an external CSS file Cascading order • Browser default • External style sheet • Internal style sheet (in the head section) • Inline style (inside an HTML element)

  50. CSS Background

More Related