Intro to PHP

  • 270 views
Uploaded on

 

More in: Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
270
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Note how the php is embedded directly in the HTML All php code is enclosed within the tag <?php ?> 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)

Transcript

  • 1. Intro to PHP Carl-Erik Svensson
  • 2. 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
  • 3. 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
  • 4. The Basics
  • 5. The Results
    • Output from a script goes directly into the HTML that is parsed
    • This is what is meant by a ‘dynamic’ webpage
  • 6. Some Syntax
    • Generally C-like
    • Variables are not strongly typed
  • 7. Web Applications
    • Form processing
    • Database manipulation
      • Blogs
      • Forums
      • Facebook
  • 8. 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/
  • 9. Rainfall Application
    • Read the contents of a database
    • Get the rainfall data
    • Parse the results
    • Display it
  • 10. 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
  • 11. Making a Query
    • Once a link is established, querying is easy
    • Errors for any given function are returned by mysql_error()
  • 12. MySQL Result Set
    • The value returned by mysql_query() is a reference to an internal data structure
    • It can be parsed by various functions
  • 13. Associative Arrays
    • An array that can be indexed by a string
    • A set of key->value pairs
    • Very similar to a hash in Perl
  • 14. PHP foreach
    • Similar to the Perl equivalent
    • Allows iterating through each element of an array
  • 15. Put it All Together
  • 16.  
  • 17. The Results http://128.174.242.224/PHPExamples/rainfall.php
  • 18. 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
  • 19.  
  • 20. Samples
    • USGS Example Rainfall
    • EC Awards Committee Scholarship Database
  • 21. What Else Can PHP Do?
    • Command line scripting
    • Desktop applications
    • Anything
  • 22. Links
    • PHP.net
    • PHP Manual
    • MySQL