1 / 10

Misc Odds and Ends

Misc Odds and Ends. CSCI 297 Scripting Languages. Today. Database Normalization Data Backups Tracking the User with Cookies. Database Normalization. Goal = each piece of information exists only once in the database creates storage efficiency more efficient to update

vadin
Download Presentation

Misc Odds and Ends

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Misc Odds and Ends CSCI 297 Scripting Languages

  2. Today • Database Normalization • Data Backups • Tracking the User with Cookies

  3. Database Normalization • Goal= each piece of information exists only once in the database • creates storage efficiency • more efficient to update • duplicates can create inaccuracies • First Normal Form • no repeating columns with same data types • all columns contain single value • primary key uniquely identifies each row • Second Normal Form • rows do not duplicate information • Third Normal Form • data not dependent on the primary key is moved to another table

  4. First Order two columns w/ same data type Normalization Example Second Order two rows with same info

  5. Backing Up Data • Full Database Back Up • big pain • two possible options from the command line: • mysqldump --opt --all-database > all.sql • mysqlhotcopydatabase /path/for/backup • Full Database Restore • it's really long set of complicated steps • If concerned about data corruption • lock the table(s) • copy the records to a copy of the table(s) • unlock the table(s) • Transactions- updates can be temporary

  6. Cookies- setting in PHP setcookie(name, value, expire, path, domain); • name • name of the cookie value • example: "usrname" • value • the value of the cookie • example = "Bob Smith" • expire • time of when the cookie expires • if empty, then the cookie expires when the browser closes • example : 24 hours from now = time()+24*60*60

  7. Cookies- very simple example • Problem : • Script to either display the user name that is stored in a cookie or save the user name into a cookie • Possible Conditions while running the script: • a cookie was already set • isset ($_COOKIE[…]) • the cookie is being set with form data • isset ($_POST[…]) • the cookie has not been set • neither of the above is true

  8. <?php // we have been here before and the cookie is set if (isset($_COOKIE["usrname"])) echo "Welcome " . $_COOKIE["usrname"] . "<P>"; // script is setting the cookie, expires in two minutes else if (isset($_POST['usrname'])) { setcookie ("usrname", $_POST['usrname'], time()+120); echo "Setting the cookie<P>"; } // first time visitor else { echo "Welcome first time visitor<P>"; echo "<form action='cooktest1.php' method='Post'>"; echo "User Name: <input type='text' name='usrname'><br>"; echo "<input type=submit value='Save Name'<P>"; echo "</form>"; } ?>

  9. Cookies- common error • The setcookie() function must appear before the <html> tag. • This code is okay: else if (isset($_POST['usrname'])) { setcookie ("usrname", $_POST['usrname'], ... echo"The cookie is set.<P>"; } • This code generates an error: else if (isset($_POST['usrname'])) { echo "Setting the cookie...<P>"; setcookie ("usrname", $_POST['usrname'], ... }

  10. Other PHP topics • Objects • Exception Handling • Authentication

More Related