End HTML SIMPLE PHP SCRIPT opening & closing PHP tags Note that PHPcode is embedded inside the HTML code. DEMO 1 PHP HTML"> End HTML SIMPLE PHP SCRIPT opening & closing PHP tags Note that PHPcode is embedded inside the HTML code. DEMO 1 PHP HTML">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP ( PHP: Hypertext Preprocessor)PHP ( PHP: Hypertext Preprocessor) Much of its syntax is borrowed from C, Java, and Perl.Much of its syntax is borrowed.

Similar presentations


Presentation on theme: "PHP ( PHP: Hypertext Preprocessor)PHP ( PHP: Hypertext Preprocessor) Much of its syntax is borrowed from C, Java, and Perl.Much of its syntax is borrowed."— Presentation transcript:

1 PHP ( PHP: Hypertext Preprocessor)PHP ( PHP: Hypertext Preprocessor) Much of its syntax is borrowed from C, Java, and Perl.Much of its syntax is borrowed from C, Java, and Perl. Since PHP is executed on the web server, web browsers can’t see your PHP code.Since PHP is executed on the web server, web browsers can’t see your PHP code. PHP is completely free (Open Source)PHP is completely free (Open Source) Support authentication, XML, dynamic image creation, and cookies.Support authentication, XML, dynamic image creation, and cookies. AN INTRODUCTION TO PHP

2 Version 4.0.0 released 22.05.2000Version 4.0.0 released 22.05.2000 An HTML scripting languageAn HTML scripting language Server-sideServer-side Cross-platformCross-platform Embedded in HTML documentsEmbedded in HTML documents ExtensibleExtensible Supports a number of protocols such as IMAP, SNMP, NNTP, and POP3.Supports a number of protocols such as IMAP, SNMP, NNTP, and POP3.

3 Begin HTML <?php echo ”My first PHP program"; ?> End HTML SIMPLE PHP SCRIPT opening & closing PHP tags Note that PHPcode is embedded inside the HTML code. DEMO 1 PHP HTML

4 PHP DATABASE CONNECTIVITY One of PHP's greatest strengths is its easy interface to a wide variety of databases. Current database modules include: MySQL InterBase PostgreSQL dBaseFrontBase Informix Microsoft SQL Server Sybase mSQL ODBC Oracle Ingres IBM DB2

5 A QUICK PLAY WITH MySQL Running the MySql Client : > mysql -uroot -p1234 your shell account username password Name Age Course Mohan 22 IT Sarina 21 EE Hong 20 IT an interface of MySQL DEMO - during your lab session

6 <?php //list_db.php $link_id = mysql_connect("localhost", "phpuser", "phppass"); $result = mysql_list_dbs($link_id); $num_rows = mysql_num_rows($result); while($db_data = mysql_fetch_row($result)) { echo $db_data[0]. " "; $result2 = mysql_list_tables($db_data[0]); $num_rows2 = mysql_num_rows($result2); while($table_data = mysql_fetch_row($result2)) echo "--". $table_data[0]. " "; echo "==> $num_rows2 table(s) in ". $db_data[0]. " "; } ?> values can be replaced To create a connection to MySQL server Close connection mysql_close ($link_id) These function will be explain during our lab session

7 MySQL BASIC COMMANDS database’s name Text file list of MySQL commands

8 THE DIFFERENCES BETWEEN PHP AND VBScript (ASP )

9

10

11

12 Function, classeshttp://php.weblogs.com/php_jscript_vbscript_2 PHP and ASP objectshttp://php.weblogs.com/php_asp_objects

13 MANIPULATING DATA IN MySQL USING PHP Getting Data From Clients To see how PHP can easily pick up and use the values transmitted by pure HTML markup To see how we can use PHP to get information back from all of these types of controls ( text field,check box,radio button etc.) To see how to submit all the data to MySQL

14 An example :  doesn’t have any PHP Script  will be pure HTML  retrieves information posted by the user  Submit to MySQL  sends the information from the web server and scripting engine back to the browser File 1 : form.html File 2: submitform.php MySQL

15 NAME : COURSE : <COURSE : Information Technology Electrical Engineering form.html One of the ways in sending information Form control’s name different name

16 GENDER: Male <INPUT TYPE="radio" NAME="radiobutton" VALUE="Female” CHECKED> Female What price of PC are you looking to buy ? RM 3000- RM 3500 RM 3500-RM 4000 RM 4000-RM 4500 TYPE attribute

17 <? $link_id = mysql_connect("localhost", "root", "faridah"); mysql_select_db("try"); $query = "INSERT INTO try1 VALUES ('$name','$checkbox1''$checkbox2','$radiobutton’,’$price’) $result = mysql_query($query); mysql_close($link_id); ?> submitform.php SQL statement DEMO 2 Additional notes will be given to you during your lab session PHP variables - which have exactly the same name as the control that have been setting in form.html Connect to MySQL

18 WHY PHP ? ( comparison with ASP ) 1.SPEED ASP will probably never be as fast as PHP. WHY ? ASP - is built on a COM-based architecture All this COM overhead adds up and slows things down. PHP modules - run in PHP's memory space. So, PHP code will run faster because - no overhead of communicating with different COM objects in different processes.

19 2.Superior Memory Management Scene : ASP’s model ( IIS 4) - Include file header.asp into 20 web pages. Then ? 20 compiled copies of that header.asp are maintained in memory This is unlike PHP, which only loads include files that are required.

20 3.Cost PHP is free ( Open Source). Some of PHP modules can be free downloaded from Internet. Microsoft is constantly tuning ASP. Users have to pay Microsoft for being used their products. Scene : Need encryption -- buy ASPEncrypt. Need email management -- buy ServerObject's QMail. Need file uploading -- buy Software Artisans SA- FileUp.

21 4.No Show Stopper Bugs Microsoft do not release ASP code. Problem? - Only Microsoft is able to fix that problem. PHP- even if you don't have the expertise in-house to fix the bug, you can definitely hire the expertise. There are no show-stoppers in PHP. Your investment is protected by the Open Source nature of PHP.

22 5.Style of Programming PHP is easier than ASP ?…Any ideas ? Personal opinion : PHP is a better or easier language to learn than VBScript ( for ASP ) because it is closer to common programming language such as C, Java etc.

23 DON’T FORGET TO CHECK OUT! http://www.php.net/ http://www-106.ibm.com/developerworks/library/web-php/ http://www.phphelp.com/tutorial/ http://www.phpbuilder.com/ Title : Beginning PHP 4.0 ( ISBN :1861003730 ) Author :Chris Lea, Wankyu Choi, Allan Kent, Ganesh Prasad, Chris Ullman. Publisher : Wrox Press Inc Title : Core PHP Programming: Using PHP to Build Dynamic Web Sites ( ISBN: 0130893986 ) Author :Leon Atkinson Publisher : Prentice Hall REFERENCES


Download ppt "PHP ( PHP: Hypertext Preprocessor)PHP ( PHP: Hypertext Preprocessor) Much of its syntax is borrowed from C, Java, and Perl.Much of its syntax is borrowed."

Similar presentations


Ads by Google