100 likes | 201 Views
Internet Applications. Spring 2008. Review. Last week Open Source LAMP/Blog exercise Questions?. This week. Guest Speaker – David Walbert of LearnNC MySQL and PHP Exercises 6 & 7. Skills needed for exercises 6 & 7. Ex 6 – MySQL SQL syntax MySQL functions in PHP
E N D
Internet Applications Spring 2008
Review • Last week • Open Source • LAMP/Blog exercise • Questions?
This week • Guest Speaker – David Walbert of LearnNC • MySQL and PHP • Exercises 6 & 7
Skills needed for exercises 6 & 7 • Ex 6 – MySQL • SQL syntax • MySQL functions in PHP • Ex 7 – Forms & form processing • Form coding and actions • Global variables • Page Logic
MySQL • Open Source Relational Database • http://mysql.com • At SILS • pearl.ils.unc.edu • Relational database features • Tables, Indexes, Queries • SQL (Structured Query Language)
SQL Skills • SQL – Structured query language • Uses a syntax with words like (select, where, insert, delete, from) to create logical statements • Select column from tablename where limit = ‘value’; • Insert into table (column, column) values (value 1, value 2); • A good reference • http://www.w3schools.com/sql/sql_quickref.asp
SQL Examples • SELECT statements • SELECT * from feeds where username = 'mitcheet'", • SELECT * from feeds where id = ".$_REQUEST['feed'] • INSERT statements • INSERT INTO feeds (username, feedname, feedURL) values ('".$_REQUEST['username']."', '".$_REQUEST['feedName']."', '".$_REQUEST['feedUrl']."')"; • DELETE statements • DELETE from feeds where id = ".$_REQUEST['feedId']
MySQL functions in PHP • Create a connection to the database • $connection = mysql_connect($dbserver, $username, $pass); • Select a database • mysql_select_db($database, $connection); • Run a query • $result = mysql_query("SELECT * from feeds where username = 'mitcheet'", $connection); • Get the results of the query as an array • while ($row = mysql_fetch_array($result, MYSQL_NUM)) {} • Close the connection • mysql_close($connection);
MySQL Example function showFeed () { $connection = mysql_connect ("pearl.ils.unc.edu", "inls572_spring08", "yreuq572"); mysql_select_db("inls572_spring08", $connection); $result = mysql_query("SELECT * from feeds where id = ".$_REQUEST['feed'], $connection); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo $row[3]; } }
Next week • Wrap-up our exercises • More on JavaScript & Ajax • Cookies & maintaining page state • Class time to work on exercises or final project