intro to php carl-erik svensson. what is php? php is a widely-used general-purpose scripting...
TRANSCRIPT
![Page 1: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/1.jpg)
Intro to PHP
Carl-Erik Svensson
![Page 2: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/2.jpg)
What is PHP?
• PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML*
*Source: http://www.php.net
![Page 3: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/3.jpg)
Why Use PHP?
• Simple, yet powerful scripting tool
• Easily format and display database information
• It is popular
Image Source: http://www.securityspace.com/s_survey/data/man.200709/apachemods.html
![Page 4: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/4.jpg)
The Basics
![Page 5: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/5.jpg)
The Results
• Output from a script goes directly into the HTML that is parsed
• This is what is meant by a ‘dynamic’ webpage
![Page 6: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/6.jpg)
Some Syntax
• Generally C-like• Variables are not strongly typed
![Page 7: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/7.jpg)
Web Applications
• Form processing
• Database manipulation
– Blogs– Forums– Facebook
![Page 8: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/8.jpg)
PHP + MySQL = Sweet
• MySQL is an open source database software solution
• Enables rich web applications when combined with PHP
Image Source: http://www.mysql.com/
![Page 9: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/9.jpg)
Rainfall Application
• Read the contents of a database
• Get the rainfall data
• Parse the results
• Display it
![Page 10: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/10.jpg)
Connecting to a Database
• PHP Has a set of functions that can be used with MySQL
• First step is to setup a link to the desired database
![Page 11: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/11.jpg)
Making a Query
• Once a link is established, querying is easy• Errors for any given function are returned by
mysql_error()
![Page 12: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/12.jpg)
MySQL Result Set
• The value returned by mysql_query() is a reference to an internal data structure
• It can be parsed by various functions
![Page 13: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/13.jpg)
Associative Arrays
• An array that can be indexed by a string• A set of key->value pairs• Very similar to a hash in Perl
![Page 14: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/14.jpg)
PHP foreach
• Similar to the Perl equivalent• Allows iterating through each element of an
array
![Page 15: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/15.jpg)
Put it All Together
![Page 16: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/16.jpg)
![Page 17: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/17.jpg)
The Results
http://128.174.242.224/PHPExamples/rainfall.php
![Page 18: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/18.jpg)
A Slight Improvement
• This was not the exact code we came up with
• I added some titles and a neat trick– Highlight every other row in the table– This makes information more readable
![Page 19: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/19.jpg)
![Page 20: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/20.jpg)
Samples
• USGS Example Rainfall
• EC Awards Committee Scholarship Database
![Page 21: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/21.jpg)
What Else Can PHP Do?
• Command line scripting
• Desktop applications
• Anything
![Page 22: Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and](https://reader035.vdocuments.mx/reader035/viewer/2022062422/56649f0c5503460f94c1f211/html5/thumbnails/22.jpg)
Links
• PHP.net• PHP Manual• MySQL• w3schools.com