0% found this document useful (0 votes)
13 views

Intro To PHP: Carl-Erik Svensson

PHP is a widely-used scripting language suited for web development. It allows embedding code into HTML pages to dynamically generate content from databases. PHP scripts can connect to databases like MySQL to read and write data and display it on web pages. When combined with a database, PHP enables building rich web applications like blogs, forums, and websites.

Uploaded by

Trisha Angel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Intro To PHP: Carl-Erik Svensson

PHP is a widely-used scripting language suited for web development. It allows embedding code into HTML pages to dynamically generate content from databases. PHP scripts can connect to databases like MySQL to read and write data and display it on web pages. When combined with a database, PHP enables building rich web applications like blogs, forums, and websites.

Uploaded by

Trisha Angel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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 can be
embedded into HTML*

*Source: http://www.php.net
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
The Basics
The Results
• Output from a script
goes directly into the
HTML that is parsed
• This is what is
meant by a
‘dynamic’ webpage
Some Syntax

• Generally C-like
• Variables are not strongly typed
Web Applications
• Form processing
• Database manipulation

– Blogs
– Forums
– Facebook
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/


Rainfall Application
• Read the contents of a database
• Get the rainfall data
• Parse the results
• Display it
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
Making a Query
• Once a link is established, querying is easy
• Errors for any given function are returned by
mysql_error()
MySQL Result Set
• The value returned by mysql_query() is a
reference to an internal data structure
• It can be parsed by various functions
Associative Arrays
• An array that can be indexed by a string
• A set of key->value pairs
• Very similar to a hash in Perl
PHP foreach
• Similar to the Perl equivalent
• Allows iterating through each element of an
array
Put it All Together
The Results

http://128.174.242.224/PHPExamples/rainfall.php
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
Samples
• USGS Example Rainfall
• EC Awards Committee Scholarship
Database
What Else Can PHP Do?
• Command line scripting
• Desktop applications
• Anything
Links
• PHP.net
• PHP Manual
• MySQL
• w3schools.com

You might also like