1 / 119

PHP (and a little MySQL) for the Default Library Techie

PHP (and a little MySQL) for the Default Library Techie. Lisa Bartle, Reference Librarian Cal. State University, San Bernardino LBartle@csusb.edu 909-537-7552 An Infopeople Workshop.

linus
Download Presentation

PHP (and a little MySQL) for the Default Library Techie

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. PHP (and a little MySQL) for the Default Library Techie Lisa Bartle, Reference Librarian Cal. State University, San Bernardino LBartle@csusb.edu 909-537-7552 An Infopeople Workshop PHP (and a Little MySQL) for the Default Library Techie Summer 2006 - This material has been created by Lisa Bartle for the Infopeople Project [infopeople.org], supported by the U.S. Institute of Museum and Library Services under the provisions of the Library Services and Technology Act, administered in California by the State Librarian. Any use of this material should credit the author and funding source.

  2. Introductions • Lab assistant • Participants • Name • Position • What you hope to do with PHP

  3. Assumptions for This Class PHP (and a Little MySQL) for the Default Library Techie • You know html code (e.g., tables, forms). • You understand the basics of databases (e.g., fields, records, truncation). • A little programming experience in any language is useful for this class but not essential (for example, you know what a variable is).

  4. Goals for This Class PHP (and a Little MySQL) for the Default Library Techie • Not to teach everything about PHP, but provide the basic knowledge for an online database. • Explain just the code, not setting up a server. • Provide a solid grounding so the books are not as formidable.

  5. Diagram of Web Applications PHP (and a Little MySQL) for the Default Library Techie Borrowed from MySQL/PHP Database Applications, 2nd ed. by Brad Bulger, Jay Greenspan, and David Wall.

  6. What is PHP? PHP (and a Little MySQL) for the Default Library Techie A scripting language most suitable for online database management.

  7. PHP Benefits PHP (and a Little MySQL) for the Default Library Techie • Open source, so it’s free • Hosting is inexpensive • PHP can be embedded in html files using .php file extension • Easy to learn • Works powerfully and intimately with MySQL and the web

  8. PHP More Benefits PHP (and a Little MySQL) for the Default Library Techie • Works well with Apache – also open source • Parse complex strings • Communicate with many credit card processing systems • Communicate with many protocols, including IMAP & POP3 (email), NNTP (usenet), and DNS (hostnames & addresses) • Native database support for over 25 db products including dBase, FilePro, FrontBase, IBM DB2, Hyperwave, mSQL, MySQL, Sybase, Unix dbm, Access, and many others • Access may be more difficult to connect

  9. Who’s Using PHP? PHP (and a Little MySQL) for the Default Library Techie Go to http://www.php.net/usage.php to find current usage statistics. http://www.abc-lit.com

  10. Recommendationsfor Text Editors PHP (and a Little MySQL) for the Default Library Techie • EditPlus2 from ES-Computing (free) • NoteTab Light from Fookes Software (free) • PHP Designer from MP Software (free) • Crimson Editor from Ingyu Kang (free)

  11. PHP (and a Little MySQL) for the Default Library Techie It All Starts with the DatabaseThe MySQL Connection

  12. What is MySQL? PHP (and a Little MySQL) for the Default Library Techie • A database system often used for web-accessible databases • A relational database management system (RDMS), like Microsoft’s Access, using SQL

  13. MySQL Introduction PHP (and a Little MySQL) for the Default Library Techie • Pronounced “My Ess Que Ell,” according to the MySQL reference manual. • Can handle small databases or very large ones (ex. 50 million records, 60,000 tables and about 5,000,000,000 rows; maximum table size is 65536 terabytes, but operating systems have limitations). • Look at the MySQL reference manual (downloads.mysql.com/docs/refman-5.0-en.pdf).

  14. MySQL Benefits PHP (and a Little MySQL) for the Default Library Techie • Open source, so it’s free • Designed to work intimately with PHP and the web • Dependable code back to 1980s and fully backward compatible • Can operate with a variety of operating systems: • Unix; FreeBSD; Mac OS X; Solaris; Windows 9x, Me, NT, 2000, XP, and Server 2003(Microsoft products are not the best with MySQL)

  15. How Is Your Data Stored? PHP (and a Little MySQL) for the Default Library Techie • Access • Excel • Something else

  16. If You Have Data … PHP (and a Little MySQL) for the Default Library Techie • Using Access or Excel you may want to convert to MySQL using an online converter • Intelligent Converters has several for-fee programs at http://www.convert-in.com

  17. If You Don’t Have Data … PHP (and a Little MySQL) for the Default Library Techie • Create a database using MySQL client

  18. More If You Don’t Have Data … PHP (and a Little MySQL) for the Default Library Techie • Create a database using Access or Excel • Create a database using phpMyAdmin • a tool written in PHP for the administration of a MySQL server over the Web • often included with the operating system

  19. phpMyAdmin Table Creation PHP (and a Little MySQL) for the Default Library Techie

  20. To Maintain Your Data PHP (and a Little MySQL) for the Default Library Techie • Use Access or Excel to update, then convert to MySQL using a converter

  21. MySQL data PHP (and a Little MySQL) for the Default Library Techie INSERT INTO 'people' VALUES('Joann', 'M', 'Aardappel', "", 'Pine Bluff', 'AR', 'Fontana', 'CA', 'San Bernardino County Sun', '2000-10-09'); INSERT INTO 'people' VALUES('Louie', 'R', 'Aboytes', "", 'Mesa', 'AZ', 'Loma Linda', 'CA', 'San Bernardino County Sun', '2001-01-05'); INSERT INTO 'people' VALUES('Edith', "", 'Abramson', 'Gimble', 'St. Paul', 'MN', 'Redlands', 'CA', 'San Bernardino County Sun', '2000-11-18'); INSERT INTO 'people' VALUES('Antonia', "", 'Acevedo', 'Bermudez', "", 'Mexico', 'Fontana', 'CA', 'San Bernardino County Sun', '2000-11-14');

  22. To Maintain Your Data PHP (and a Little MySQL) for the Default Library Techie • Use Access or Excel to update, then convert to MySQL using a converter • Use phpMyAdmin to update

  23. phpMyAdmin Data Input PHP (and a Little MySQL) for the Default Library Techie

  24. Housekeeping PHP (and a Little MySQL) for the Default Library Techie • Open Internet Explorer • Go to Tools > Internet Options > Advanced • Put an X next to: Enable folder view for FTP sites

  25. PHP (and a Little MySQL) for the Default Library Techie Our Project Go to http://phpclass.infopeople.org/search.html

  26. PHP (and a Little MySQL) for the Default Library Techie The PHP Connection

  27. PHP (and a Little MySQL) for the Default Library Techie PHP Start and Stop • PHP code starts <?php • PPH code ends ?> example1.php

  28. PHP (and a Little MySQL) for the Default Library Techie Comments • Explain the purpose of the coding • Help you and others read the code • Help you when you’ve forgotten what it all means

  29. PHP (and a Little MySQL) for the Default Library Techie Comment Structure // begin each line inside the PHP code # begin each line inside the PHP code /* begin and */ end several lines inside the PHP code

  30. PHP (and a Little MySQL) for the Default Library Techie Comment Examples <?php //Purpose: to create a form for patrons’ questions ?> ---------------------------- <?php ###### Show Results to User ###### ?> ---------------------------- <?php /* Purpose: to create a form for patrons’ questions Author: Lisa Bartle Date: Nov. 6, 2006 */ ?>

  31. PHP (and a Little MySQL) for the Default Library Techie Exercise 1 Open up Notepad and get to coding!

  32. PHP (and a Little MySQL) for the Default Library Techie “Hello_Librarians”:First PHP Example <h2>Infopeople PHP class</h2> <?php print "<p>Hello librarians!"; ?> Code User Sees example1.php

  33. PHP (and a Little MySQL) for the Default Library Techie PHP and HTML • HTML can be outside of PHP coding • HTML can be inside of the code, but must be inside quotation marks with a print statement • PHP statements end in a semi-colon example1.php

  34. PHP (and a Little MySQL) for the Default Library Techie Outputting Data • Echo -- a language construct or structure for a single argument. • Print -- a language construct, which can have multiple arguments and more complex expressions. We will use PRINTin this class.

  35. PHP (and a Little MySQL) for the Default Library Techie Echo & Print Example <?php Echo "Infopeople PHP Presentation"; Print "<P>Hello librarians."; ?> Code User Sees example2.php

  36. PHP (and a Little MySQL) for the Default Library Techie What is a Variable? • A variable is a place to store information. • Information stored in a variable can be defined by the programmer. • Information stored in a variable can come from a user using a form.

  37. PHP (and a Little MySQL) for the Default Library Techie Variables • A variable always begins with a $ then the variable name. • Variables are case sensitive and alpha-numeric. • Do not start a variable with a number. • All the variables below are different. • $book • $amount • $Amount • $AmoUnT • $AMOUNT

  38. PHP (and a Little MySQL) for the Default Library Techie Variable Example <?php Print "<h2>Infopeople PHP Presentation </h2><br>"; print "<p>Hello librarians! <br>"; $date="Nov. 6, 2006"; print "Today’s date is $date"; ?> example3.php

  39. PHP (and a Little MySQL) for the Default Library Techie Printing Variables <?php $date="Nov. 6, 2006"; print "Today’s date is $date"; Print "Today’s date is "; print $date; ?> example3.php

  40. PHP (and a Little MySQL) for the Default Library Techie Date Function • Use date() to display the date and time • Can display in multiple ways • Jul. 12, 2006 • July 12, 2006 • 7/12/2006 • 2006/07/12 example7.php

  41. PHP (and a Little MySQL) for the Default Library Techie Date Display $datedisplay=date("Y/m/d"); print $datedisplay; # If the date is November 6, 2005 # It would display as 2005/11/06 $showdate=date("l, F j, Y"); print $showdate; # If the date is November 6, 2005 # It would display as # Sunday, November 6, 2005 See handout “Displaying the Date Using Date()” example7.php

  42. PHP (and a Little MySQL) for the Default Library Techie Exercise 2 Open up Notepad and get to coding!

  43. PHP (and a Little MySQL) for the Default Library Techie Profession Example profession.php

  44. PHP (and a Little MySQL) for the Default Library Techie The HTML Connection

  45. PHP (and a Little MySQL) for the Default Library Techie Forms Forms provide an interface for users to query your database.

  46. PHP (and a Little MySQL) for the Default Library Techie Forms HTML <-- form tag goes before the form objects --> <form> [form objects go here] [radio buttons, pull-down menus, text boxes] [submit button, cancel button] </form>

  47. PHP (and a Little MySQL) for the Default Library Techie Radio Buttons <INPUT type="radio" name="sex" value="M"> Male<BR> <INPUT type="radio" name="sex" value="F"> Female<BR> Name becomes the variable name. Value is what the variable is holding. example9.html

  48. PHP (and a Little MySQL) for the Default Library Techie Pull-Down Menus <p>City of death: <select name="deathcity" size="1"> <option selected value="">Search all cities in database</option> <option value="Fontana">Fontana</option> <option value="Loma Linda">Loma Linda</option> <option value="Redlands">Redlands</option> <option value="San Bernardino">San Bernardino</option> <option value="Victorville">Victorville</option> </select> Name =variable name. Value =what variable is holding. example10.html

  49. PHP (and a Little MySQL) for the Default Library Techie Text Boxes <input TYPE= "text" NAME="anyname" SIZE="20" MAXLENGTH="40"> Name =variable name. example11.html

  50. PHP (and a Little MySQL) for the Default Library Techie Check Boxes Libraries should get more<p> <input TYPE="checkbox" NAME="money" VALUE="Yes" checked> Money <br> <input TYPE="checkbox" NAME="respect" VALUE="Yes"> Respect Name=variable name Value=what variable is holding. example13.html

More Related