Intro to PHP Carl-Erik Svensson
What is PHP? <ul><li>PHP is a widely-used general-purpose scripting language that is especially suited for Web development...
Why Use PHP? <ul><li>Simple, yet powerful scripting tool </li></ul><ul><li>Easily format and display database information ...
The Basics
The Results <ul><li>Output from a script goes directly into the HTML that is parsed </li></ul><ul><li>This is what is mean...
Some Syntax <ul><li>Generally C-like </li></ul><ul><li>Variables are not strongly typed </li></ul>
Web Applications <ul><li>Form processing </li></ul><ul><li>Database manipulation </li></ul><ul><ul><li>Blogs </li></ul></u...
PHP + MySQL = Sweet <ul><li>MySQL is an open source database software solution </li></ul><ul><li>Enables rich web applicat...
Rainfall Application <ul><li>Read the contents of a database </li></ul><ul><li>Get the rainfall data </li></ul><ul><li>Par...
Connecting to a Database <ul><li>PHP Has a set of functions that can be used with MySQL </li></ul><ul><li>First step is to...
Making a Query <ul><li>Once a link is established, querying is easy </li></ul><ul><li>Errors for any given function are re...
MySQL Result Set <ul><li>The value returned by mysql_query() is a reference to an internal data structure </li></ul><ul><l...
Associative Arrays <ul><li>An array that can be indexed by a string </li></ul><ul><li>A set of key->value pairs </li></ul>...
PHP foreach <ul><li>Similar to the Perl equivalent </li></ul><ul><li>Allows iterating through each element of an array </l...
Put it All Together
 
The Results http://128.174.242.224/PHPExamples/rainfall.php
A Slight Improvement <ul><li>This was not the exact code we came up with </li></ul><ul><li>I added some titles and a neat ...
 
Samples <ul><li>USGS Example Rainfall </li></ul><ul><li>EC Awards Committee Scholarship Database </li></ul>
What Else Can PHP Do? <ul><li>Command line scripting </li></ul><ul><li>Desktop applications </li></ul><ul><li>Anything </l...
Links <ul><li>PHP.net </li></ul><ul><li>PHP Manual </li></ul><ul><li>MySQL </li></ul>
Upcoming SlideShare
Loading in …5
×

Intro to PHP

536 views
441 views

Published on

Published in: Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
536
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Note how the php is embedded directly in the HTML All php code is enclosed within the tag &lt;?php ?&gt; Echo function prints out a string to the output stream In this case the output stream is the actual HTML document
  • * Note that all variables begin with a $ sign, even arrays and objects
  • Now that we know the basics, lets see what we can do
  • Facebook uses mysql Being open source has many advantages - continually improving, highly available, free (mostly)
  • Intro to PHP

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

    ×