Assignment help PHP MySQL crash course - PowerPoint PPT Presentation

About This Presentation
Title:

Assignment help PHP MySQL crash course

Description:

Assignment help PHP + MySQL crash course Gyozo Gidofalvi Assignment Implement a movie database with a web front-end using the Linux-Apache-MySQL-PHP, or LAMP, Web ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 9
Provided by: itUuSeed
Category:

less

Transcript and Presenter's Notes

Title: Assignment help PHP MySQL crash course


1
Assignment help PHP MySQL crash course
  • Gyozo Gidofalvi

2
Assignment
  • Implement a movie database with a web front-end
    using the Linux-Apache-MySQL-PHP, or LAMP, Web
    development framework
  • To be completed in groups (3-5)
  • Deploy solution
  • See me in the lab to get a MySQL account for your
    group
  • Demo your solution during the scheduled labs

3
Connecting to MySQL from PHP
  • lt?
  • link mysql_connect(hostname, username,
    password)
  • or die("Could not open connection to
    database")
  • ?gt
  • Now the variable link contains the information
    for your connection to MySQL. You can disconnect
    using
  • lt?
  • mysql_close(link)
  • or die("Could not close connection to
    database")
  • ?gt

4
Select a database, issue queries
  • Once you have connected successfully, you should
    select the database you will use. Then you can
    issue queries to the database.
  • lt?
  • mysql_select_db(ecomXXXX", link)
  • or die("Could not select database")
  • result mysql_query("select from
    some_table")
  • or die("Could not issue MySQL query")
  • ?gt
  • Now the variable result will be used to
    reference the query we just made.

5
Array handling in PHP
  • In PHP, arrays are associative. Any number or
    string can be used to index an array.
  • lt?
  • array"hello" 3
  • array5 "how are you?"
  • while (list(column, value) each(array))
  • print("column value\n")
  • reset(array)
  • ?gt
  • This example would print
  • hello 3
  • 5 how are you?
  • The command reset(array) puts the array iterator
    back to the beginning of the array.

6
Getting the results from a query
  • After issuing a query, you retrieve the results
    using the variable result.
  • lt?
  • if (mysql_num_rows(result) 0)
  • print("No results matching your
    queryltBRgt\n")
  • else
  • print("Here are the resultsltBRgt\n")
  • while (row mysql_fetch_row(result))
  • while (list(colname, value) each(row))
  • print("value ")
  • print("ltBRgt\n")
  • ?gt

7
HTML forms and PHP variables
  • From an HTML page that had this form
  • ltFORM ACTION"target.php" METHOD"GET"gt
  • ltINPUT TYPE"TEXT" NAME"myvar"gt
  • ltINPUT TYPE"TEXT" NAME"yourvar"gt
  • ltINPUT TYPE"SUBMIT" NAME"submit"gt
  • lt/FORMgt
  • The PHP script (target.php) will receive the
    variables from the form by the same name
  • lt?
  • print("you entered myvar _GETmyvar,
    yourvar _GETyourvar\n")
  • ?gt

8
Useful string stuff in PHP
  • Difference between single and double quotes
  • lt?
  • name "Joe"
  • print("hello, your name is name\n")
  • print(hello, your name is name\n)
  • ?gt
  • Output hello, your name is Joe
  • hello, your name is name
  • trimmed trim(" this string has whitespace ")
    removes leading and trailing whitespace
  • encoded urlencode("this is a non-encoded url
    string") changes the argument so that it will be
    part of a valid URL
Write a Comment
User Comments (0)
About PowerShow.com