php basic fundamentals - chapter 2

27
PHP

Upload: apex-tgi

Post on 21-Dec-2015

23 views

Category:

Documents


0 download

DESCRIPTION

WampServer is a local server package for Windows, allowing you to install and host web applications that use Apache, PHP and MySQL. This article will walk you through the steps to install WampServer on your computer.

TRANSCRIPT

Page 1: PHP Basic Fundamentals - Chapter 2

PHP

Page 2: PHP Basic Fundamentals - Chapter 2

… Contine from Slide1

Link of Slide 1 :

http://www.slideshare.net/apextgi/php-basic-fundamentals-a-quick-review

Page 3: PHP Basic Fundamentals - Chapter 2

It depends on how they are being sent.

• $_GET[‘varname’]• $_POST[‘varname’]• $_SESSION[‘varname’]• $_COOKIE[‘varname’]• $_REQUEST[‘varname’]• $_SERVER[‘varname’]• $_FILES[‘varname’]• $_ENV[‘varname’]

Ways to refer variable…

Page 4: PHP Basic Fundamentals - Chapter 2

There are four ways to do it.

1) Passing Variables Through a URL:Values are passed through query string.echo “<a href=’http://localhost/2.php?favmovie=ddlj’> Click here </a>”;Disadvantages:• ❑ Everyone can see the values of the variables.• ❑ The user can change the variable value in the URL,

which can lead to inconsistency of data.• ❑ Pull up inaccurate or old information using a saved URL

with older variables embedded in it.

Passing Variables Between Pages

Page 5: PHP Basic Fundamentals - Chapter 2

2) Passing Variables Through Session:A Session is a temporary set of variables that exists only until the browser has shut down. • Every session is assigned a unique session ID,

which keeps all the current information together.• To begin a session: session_start(). It must be

used at the beginning of every page.

3) Passing Variables Through Cookie:Cookies are tiny bits of information stored on Website’s visitor’s computer.• The advantage to storing information in a cookie

versus a session is longevity.• To set a cookie: setcookie(name, value, expire, path, domain);

Page 6: PHP Basic Fundamentals - Chapter 2

4) Passing Variables Through Forms:• Forms allow Web site to be truly interactive.• Forms are coded in HTML and stay in HTML.• A form is made up of four parts:

o Opening tag line, indicated by <FORM> tag. o Content of the form, including input fields.

Text Checkbox Radio Options Password

o Action button(s) or images typically submit/clear or user-defined button.

o Closing tag line, indicated with </FORM> tag.

Page 7: PHP Basic Fundamentals - Chapter 2

MySQL

• MySQL is the most popular open source database server.

• A database defines a structure for storing information.

• With MySQL, we can query a database for specific information and have a recordset returned.

Page 8: PHP Basic Fundamentals - Chapter 2

Cont…

• MySQL is ideal for both small and large applications

• MySQL supports standard SQL • MySQL compiles on a number of platforms • MySQL is free to download and use • PHP combined with MySQL are cross-

platform (means that you can develop in Windows and serve on a Unix platform)

Page 9: PHP Basic Fundamentals - Chapter 2

• MySQL is a relational database system.• It can store bits of information in separate tables

and link those tables together.• Each table consists of separate fields, which

represent each bit of information.

Field-Types:• char• varchar• int• text• decimal• time• date

Cont…

Page 10: PHP Basic Fundamentals - Chapter 2

• mysql_connect ("hostname", "user", "pass");• mysql_create_db("database name");• mysql_select_db("database name");• mysql_query("query");• mysql_fetch_rows("results variable from query");• mysql_error();

Querying the DatabaseSELECT [fieldnames]AS [alias]FROM [tablename]WHERE [criteria]ORDER BY [fieldname to sort on] [DESC]LIMIT [offset, maxrows]

Some PHP function for MySql

Page 11: PHP Basic Fundamentals - Chapter 2

Connectivity to MySQL

• In PHP, connection is established usingthe mysql_connect() function.

• Syntaxmysql_connect(servername,username,password);ex <?php$con = mysql_connect("localhost",“root",“ ");if (!$con) { die('Could not connect: ' . mysql_error()); } // some code ?>

Page 12: PHP Basic Fundamentals - Chapter 2

Closing A Connection

• The connection is closed as soon as the script ends. To close the connection usethe mysql_close() function.ex. <?php $con = mysql_connect("localhost",“root","");if (!$con) { die('Could not connect: ' . mysql_error());}// some code mysql_close($con);?>

Page 13: PHP Basic Fundamentals - Chapter 2

WAMP

WAMP Server • W :- Windows XP/Vista• A :- Apache version 2.2.6• M :- MySQL version 5.0.45• P :- PHP version 5.2.5

Page 14: PHP Basic Fundamentals - Chapter 2

Real world example Of PHP

Page 15: PHP Basic Fundamentals - Chapter 2

15

Page 16: PHP Basic Fundamentals - Chapter 2

OUTLINE

•Yahoo!, as seen by an engineer•Choosing PHP in 2002•PHP architecture at Yahoo!

Page 17: PHP Basic Fundamentals - Chapter 2

Why we picked PHP

1. Designed for web scripting2. High performance3. Large, Open Source community

• Documentation, easy to hire developers4. “Code-in-HTML” paradigm

<html><?php echo "Hello World"; ?></html>

5. Integration, libraries, extensibility6. Tools: IDE, debugger, profiler

Page 18: PHP Basic Fundamentals - Chapter 2

WAMP

WAMP Server • W :- Windows XP/Vista• A :- Apache version 2.2.6• M :- MySQL version 5.0.45• P :- PHP version 5.2.5

Page 19: PHP Basic Fundamentals - Chapter 2

UserProfileServer

web serverweb serverWeb Server

Scripts

Load B

alance

r

AdServer

Web Service

s

Web Service

s

Apache

Server Architecture

Page 20: PHP Basic Fundamentals - Chapter 2

Exception Handling

Page 21: PHP Basic Fundamentals - Chapter 2

Error Types in PHP

There are 13 predefined error constants that correspond to different types of errors in PHP. They are

•E_ERROR : Fatal runtime errors that cannot be recovered from; the execution of the script is halted .

•E_WARNING: Nonfatal runtime errors .

•E_PARSE: Compile - time parse errors .

•..............

Page 22: PHP Basic Fundamentals - Chapter 2

Cont…

•E_NOTICE : Nonfatal runtime notices that indicate that the script encountered something that might be an error, but could also happen in the normal course of running a script .•E_CORE_ERROR: Fatal errors that occur during PHP ’ s initial startup; the execution of the script is

•halted .

•E_CORE_WARNING : Nonfatal errors that occur during PHP ’ s initial startup .

Page 23: PHP Basic Fundamentals - Chapter 2

Cont…

•E_COMPILE_ERROR : Fatal compile - time errors; the execution of the script is halted .

•E_COMPILE_WARNING : Nonfatal compile - time errors .

•E_USER_ERROR : User - generated error messages (like E_ERROR , but instead generated by using by using the trigger_error() function); the execution of the script is halted .

Page 24: PHP Basic Fundamentals - Chapter 2

Cont…

•E_USER_WARNING: User - generated warning messages (like E_WARNING , but instead generated by using the trigger_error() function) .

•E_USER_NOTICE : User - generated notice messages (like E_NOTICE , but instead generated by using the trigger_error() function) .

•E_STRICT : Runtime notices that suggest changes to your code that would ensure the best interoperability and forward compatibility of your code .

Page 25: PHP Basic Fundamentals - Chapter 2

Cont…

•E_RECOVERABLE_ERROR: Catchable fatal errors that indicate that a probably dangerous error occurred, but did not leave the PHP ’ s execution engine in an unstable state .

•E_ALL : All errors and warnings combined .

Page 26: PHP Basic Fundamentals - Chapter 2

Thank You.

Page 27: PHP Basic Fundamentals - Chapter 2