php basic fundamentals - chapter 2

Post on 21-Dec-2015

24 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

PHP

… Contine from Slide1

Link of Slide 1 :

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

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…

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

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);

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.

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.

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)

• 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…

• 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

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 ?>

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);?>

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

Real world example Of PHP

15

OUTLINE

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

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

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

UserProfileServer

web serverweb serverWeb Server

Scripts

Load B

alance

r

AdServer

Web Service

s

Web Service

s

Apache

Server Architecture

Exception Handling

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 .

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

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 .

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 .

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 .

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 .

Thank You.

top related