PHP and a little MySQL for the Default Library Techie - PowerPoint PPT Presentation

1 / 119
About This Presentation
Title:

PHP and a little MySQL for the Default Library Techie

Description:

Author: Lisa Bartle. Date: Nov. 6, 2006. Exercise 1 ... Print 'Hello Lisa.'; $count=$count 1; ... Go to http://phpclass.infopeople.org/lisa/profession.php ... – PowerPoint PPT presentation

Number of Views:172
Avg rating:3.0/5.0
Slides: 120
Provided by: lisab2
Category:
Tags: mysql | php | default | library | lisa | techie

less

Transcript and Presenter's Notes

Title: PHP and a little MySQL for the Default Library Techie


1
PHP (and a little MySQL) for the Default Library
Techie
Lisa Bartle, Reference Librarian Cal. State
University, San Bernardino LBartle_at_csusb.edu 909-5
37-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 its 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
Whos 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
It All Starts with the DatabaseThe MySQL
Connection
PHP (and a Little MySQL) for the Default Library
Techie
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 Microsofts 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 its 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 Dont Have Data
PHP (and a Little MySQL) for the Default Library
Techie
  • Create a database using MySQL client

18
More If You Dont 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
Our Project
PHP (and a Little MySQL) for the Default Library
Techie
Go to http//phpclass.infopeople.org/search.html
26
The PHP Connection
PHP (and a Little MySQL) for the Default Library
Techie
27
PHP Start and Stop
PHP (and a Little MySQL) for the Default Library
Techie
  • PHP code starts
  • PPH code ends ?

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

29
Comment Structure
PHP (and a Little MySQL) for the Default Library
Techie
// begin each line inside the PHP code begin
each line inside the PHP code / begin and /
end several lines inside the PHP code
30
Comment Examples
PHP (and a Little MySQL) for the Default Library
Techie
questions ? ---------------------------- Show Results to User ? --------------
-------------- for patrons questions Author Lisa Bartle Date
Nov. 6, 2006 / ?
31
Exercise 1
PHP (and a Little MySQL) for the Default Library
Techie
Open up Notepad and get to coding!
32
Hello_LibrariansFirst PHP Example
PHP (and a Little MySQL) for the Default Library
Techie
Infopeople PHP class "Hello librarians!" ?
Code
User Sees
example1.php
33
PHP and HTML
PHP (and a Little MySQL) for the Default Library
Techie
  • 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
Outputting Data
PHP (and a Little MySQL) for the Default Library
Techie
  • 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 PRINT in this class.
35
Echo Print Example
PHP (and a Little MySQL) for the Default Library
Techie
"Hello librarians." ?
Code
User Sees
example2.php
36
What is a Variable?
PHP (and a Little MySQL) for the Default Library
Techie
  • 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
Variables
PHP (and a Little MySQL) for the Default Library
Techie
  • 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
Variable Example
PHP (and a Little MySQL) for the Default Library
Techie
Infopeople PHP Presentation

" print "Hello librarians!
"
date"Nov. 6, 2006" print "Todays date is
date" ?
example3.php
39
Printing Variables
PHP (and a Little MySQL) for the Default Library
Techie
is date" Print "Todays date is " print
date ?
example3.php
40
Date Function
PHP (and a Little MySQL) for the Default Library
Techie
  • 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
Date Display
PHP (and a Little MySQL) for the Default Library
Techie
datedisplaydate("Y/m/d") print datedisplay
If the date is November 6, 2005 It would
display as 2005/11/06
showdatedate("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
Exercise 2
PHP (and a Little MySQL) for the Default Library
Techie
Open up Notepad and get to coding!
43
Profession Example
PHP (and a Little MySQL) for the Default Library
Techie
profession.php
44
The HTML Connection
PHP (and a Little MySQL) for the Default Library
Techie
45
Forms
PHP (and a Little MySQL) for the Default Library
Techie
Forms provide an interface for users to query
your database.
46
Forms HTML
PHP (and a Little MySQL) for the Default Library
Techie
-- form objects go here radio
buttons, pull-down menus, text boxes submit
button, cancel button
47
Radio Buttons
PHP (and a Little MySQL) for the Default Library
Techie

Male
value"F" Female

Name becomes the variable name. Value is what
the variable is holding.
example9.html
48
Pull-Down Menus
PHP (and a Little MySQL) for the Default Library
Techie
City of death size"1" Search all
cities in database value"Fontana"Fontana value"Loma Linda"Loma Linda value"Redlands"Redlands value"San Bernardino"San Bernardino tion value"Victorville"Victorville lect
Name variable name. Value what variable is
holding.
example10.html
49
Text Boxes
PHP (and a Little MySQL) for the Default Library
Techie
MAXLENGTH"40"
Name variable name.
example11.html
50
Check Boxes
PHP (and a Little MySQL) for the Default Library
Techie
Libraries should get more TYPE"checkbox" NAME"money" VALUE"Yes" checked
Money
VALUE"Yes" Respect
Namevariable name Valuewhat variable is holding.
example13.html
51
Submit/Reset Buttons
PHP (and a Little MySQL) for the Default Library
Techie
it!" VALUE"Clear Form"
example14.html
52
Form Action
PHP (and a Little MySQL) for the Default Library
Techie
action"file,URL,or path" method"post" form
objects here
53
The PHP Connection
PHP (and a Little MySQL) for the Default Library
Techie
54
Operators
PHP (and a Little MySQL) for the Default Library
Techie
  • Arithmetic operators
  • Assignment operators
  • Comparison operators

See handout Operators.
55
Arithmetic Operators
PHP (and a Little MySQL) for the Default Library
Techie
a b //addition a - b //subtraction a
b //multiplication a / b //division
example6.php
56
Assignment Arithmetic Operators
PHP (and a Little MySQL) for the Default Library
Techie
total Print " total " //total is
45 ?
example6.php
57
Comparison Operators
PHP (and a Little MySQL) for the Default Library
Techie
Equal a b Not Equal a ! b a
b Less Than a to a b Greater Than
or Equal to a b
See handout Operators
58
Difference Between and
PHP (and a Little MySQL) for the Default Library
Techie
Assigns a value to a variable Checks the
value of a variable
See handout Operators.
59
If Else
PHP (and a Little MySQL) for the Default Library
Techie
If (condition) Statement Else
Statement
If (user"Lisa") Print "Hello Lisa."
Else Print "You aren't Lisa."
No THEN in PHP
60
ElseIf
PHP (and a Little MySQL) for the Default Library
Techie
If (condition) Statement Elseif
(condition) Statement Else Statement
If (user"Lisa") Print "Hello Lisa."
Elseif (user"Mo") Print "Hello Mo."
Else Print "Who are you?"
61
While Loops
PHP (and a Little MySQL) for the Default Library
Techie
Lisa." countcount 1 Another way to say
to say that is count ?
While (condition) Statement
example8.php
62
Profession Example
PHP (and a Little MySQL) for the Default Library
Techie
  • Go to http//phpclass.infopeople.org/lisa/pr
    ofession.php

profession.php
63
Questions to Think About
PHP (and a Little MySQL) for the Default Library
Techie
1. What is the first step for this code? 2.
What kind of php structures will be necessary?
example15.php
64
Exercise 3
PHP (and a Little MySQL) for the Default Library
Techie
65
Top Errors Messages
PHP (and a Little MySQL) for the Default Library
Techie
1. Missing semi-colon. 2. Misspelled variables
and missing . 3. Incomplete pairs for quotation
marks, parentheses, curly brackets, etc.
See handout Common PHP Mistakes and Error
Messages
66
Our Sample Database
PHP (and a Little MySQL) for the Default Library
Techie
  • This classs prepared database is called
    obituaries.
  • The file is obituaries.sql.
  • It is an index of peoples names who have had
    obits listed in the newspaper. It is for patrons
    genealogical research.
  • The table called people has our data.
  • Records 100
  • Fields 11


See handout Organize Your Database and Server
Information
67
Download Search.html to Your Directory
PHP (and a Little MySQL) for the Default Library
Techie
Go to http//phpclass.infopeople.org/search.html
  • Click View Source
  • Save the file as search.html
  • to your desktop.

3. Copy the file from your desktop into your
directory.
You will not need to create the search form from
scratch.
68
search.php
PHP (and a Little MySQL) for the Default Library
Techie
  • Creates connection to server database
  • Alters input for safety
  • Creates SQL query
  • Displays the results
  • Close the connection to database

69
Connect to the Server
PHP (and a Little MySQL) for the Default Library
Techie
Mysql_connect() is the function used to connect
to the server.
mysql_connect("hostaddress", "myusername",
"mypassword") or die ("message")
Die() is a function for an output message and to
terminate the current script.
70
Mysql_connect() Structure
PHP (and a Little MySQL) for the Default Library
Techie
connectionmysql_connect("hostaddress",
"myusername", "mypassword") or die ("message")
71
Mysql_connect() Example
PHP (and a Little MySQL) for the Default Library
Techie
Create connection to database Define
variables hostaddress"phpclass.phpclass. infopeo
ple.org" myusername"phpclass" mypassword"inf
opeople" connectionmysql_connect(hostaddress,
myusername, mypassword) or die ("Cant connect
to server.")
72
Close Connection
PHP (and a Little MySQL) for the Default Library
Techie
Mysql_close() is the function to close the
connection to the server.
mysql_close(connection)
73
Connect to the Database
PHP (and a Little MySQL) for the Default Library
Techie
Mysql_select_db() is the function to select your
MySQL database.
mysql_select_db("database") or die ("Message")
74
Mysql_select_db()
PHP (and a Little MySQL) for the Default Library
Techie
database"obituaries" tablename"people" re
sultmysql_select_db(database) or die("Database
could not be selected")
75
Alter Input for Safety
PHP (and a Little MySQL) for the Default Library
Techie
  • Creates connection to database
  • Alters input for safety
  • Creates SQL query
  • Displays the results
  • Close the connection to database

76
Trim(), Strip_tags(), Strtolower()
PHP (and a Little MySQL) for the Default Library
Techie
  • Trim removes whitespace at the beginning and end
    of a string.
  • Strip_tags tries to remove PHP HTML tags from a
    string.
  • Strtolower converts alpha characters to lowercase.

anynametrim(anyname) anynamestrip_tags(anyn
ame) anynamestrtolower(anyname)
search.php
77
Exercise 4
PHP (and a Little MySQL) for the Default Library
Techie
Open up Notepad and get to coding!
78
Create SQL Query
PHP (and a Little MySQL) for the Default Library
Techie
  • Creates connection to database
  • Alters input for safety
  • Creates SQL query
  • Displays the results
  • Close the connection to database

79
Concatenation
PHP (and a Little MySQL) for the Default Library
Techie
A union by chaining or linking together. Use a
period to link together strings.
ring3string1." ".string2 Print
string3 print "" Print string1."
".string2 ?
example5.php
80
Escaping the Character
PHP (and a Little MySQL) for the Default Library
Techie
If the string has a set of double quotation marks
that must remain visible, use the \ backslash
before the quotation marks so PHP does not act on
them and only displays them.
heading ?
example16.php
81
The SQL Connection
PHP (and a Little MySQL) for the Default Library
Techie
82
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.
83
What is SQL?
PHP (and a Little MySQL) for the Default Library
Techie
  • Structured Query Language
  • A database access language standard
  • All SQL-capable databases support a common subset
    of SQL
  • Access, MySQL, some Oracle databases, etc.

84
SQL Select Query Template
PHP (and a Little MySQL) for the Default Library
Techie
SELECT field,field from table WHERE field
operator parameter or input ORDER BY field
ASC or DESC
85
SQL Query Examples
PHP (and a Little MySQL) for the Default Library
Techie
Database obituariesTable peopleFields
lastname, firstname, middlename, maidenname,
newsdate, newsyear
  • SELECT lastname, firstname from people where
    newsyear 2000
  • SELECT lastname, firstname from people where
    newsyear 2000 and newsyear
  • SELECT lastname, firstname from people where
    newsyear BETWEEN 2000 and 2003

Numbers do not need quotation marks in SQL.
86
SQL Query Examples
PHP (and a Little MySQL) for the Default Library
Techie
Database obituariesTable peopleFields
lastname, firstname, middlename, maidenname,
newsdate, newsyear
  • SELECT from people where lastname "Jones"
  • SELECT from people where lastname LIKE
    "Jones"
  • SELECT from people where lastname LIKE
    "Jones"
  • SELECT from people where lastname LIKE
    "Jones" ORDER BY lastname ASC, firstname ASC

Text needs quotation marks in SQL.
87
PHP SQL in the Query
PHP (and a Little MySQL) for the Default Library
Techie
SELECT from people where lastname LIKE
"Jones" ORDER BY lastname ASC
query"SELECT from people where lastname LIKE
\"Jones\" ORDER BY lastname ASC"
88
Variables in the PHP/SQL Query
PHP (and a Little MySQL) for the Default Library
Techie
query"SELECT from people where lastname LIKE
\"Jones\" ORDER BY lastname ASC"
query"SELECT from " .tablename. " where
lastname LIKE \"" .anyname. "\" ORDER BY
lastname ASC"
89
Match Against In Boolean Mode
PHP (and a Little MySQL) for the Default Library
Techie
query"SELECT from " .tablename. " WHERE
MATCH(firstname, middlename, lastname,
maidenname) AGAINST ('anyname' IN BOOLEAN MODE)
AND newsyear " .newsyear1. " AND
newsyearASC"
RedPHP PurpleSQL
90
SQL Troubleshooting Tips
PHP (and a Little MySQL) for the Default Library
Techie
Build the SQL statement slowly, piece by
piece. Keep what is working and comment it out
so that you can start from success when you
need to start over. query"SELECT from
".tablename This works query"SELECT from
".tablename Print the query so you can tell
where it is breaking down. Print query
91
SQL Query
PHP (and a Little MySQL) for the Default Library
Techie
  • If (deathcity"") deathcityquery" "
  • else deathcityquery" and deathcity\"".deathci
    ty."\""

92
More SQL Query
PHP (and a Little MySQL) for the Default Library
Techie
  • If (anyname"")
  • query"SELECT from " . tablename. " WHERE
    newsyear ".newsyear1." AND newsyearr2.deathcityquery." ORDER BY lastname ASC"
  • else
  • query"SELECT from " . tablename. " WHERE
    match(firstname, middlename, lastname,
    maidenname) against ('anyname' in boolean mode)
    and newsyear ".newsyear1." AND
    newsyearlastname ASC"

93
Download sql_query.php
PHP (and a Little MySQL) for the Default Library
Techie
  • Sql_query.php is available in the main directory
    of the ftp server.
  • Copy the file to your desktop.
  • Open it.
  • Copy the query and place it under the header
    Create SQL Query.

94
True Boolean Queries
PHP (and a Little MySQL) for the Default Library
Techie
We have a textbox, anyname, in our obituary
search form. We want it to be Boolean searchable.
Such as
(peek or byrd) and (mary or ellen)
How do we do it?
95
Alter the Input for SQL
PHP (and a Little MySQL) for the Default Library
Techie
Think of our old AltaVista searches
alice wonderland columbia
We need to use PHP to substitute the AND, OR, NOT
that the users input so that SQL can understand
it.
96
Create Boolean String
PHP (and a Little MySQL) for the Default Library
Techie
Insert an initial plus-sign so the first
term or phrase is included as a
mandatory. addplus"" anynameaddplus.anynam
e
97
Replacing Strings
PHP (and a Little MySQL) for the Default Library
Techie
Use str_replace() to replace one string with
another.
string str_replace("find this", "replace with
this", in_ this_string)
98
Create Boolean Stringstr_replace() AND
PHP (and a Little MySQL) for the Default Library
Techie
Replace all the AND's with 's, so that
SQLs fulltext indexing can understand it.
The spacing is important here. anynamestr_replac
e(" and ", " ", anyname)
99
Create Boolean Stringstr_replace() OR
PHP (and a Little MySQL) for the Default Library
Techie
OR is assumed, so just pull those
out. anyname str_replace(" or ", " ", anyname)
100
Create Boolean Stringstr_replace() NOT
PHP (and a Little MySQL) for the Default Library
Techie
look for NOTs anynamestr_replace(" not ", "
-", anyname) Some people may put AND NOT.
Since we already replaced the ANDs and ORs,
this may look strange. anynamestr_replace("
not ", " -", anyname)
101
Mysql_query()
PHP (and a Little MySQL) for the Default Library
Techie
Where query is the constructed SQL query
mysql_query(query) or die(Message.")
resultmysql_query(query) or die("Couldnt
execute query.")
102
Exercise 5
PHP (and a Little MySQL) for the Default Library
Techie
Open up Notepad and get to coding!
103
search.php
PHP (and a Little MySQL) for the Default Library
Techie
  • Creates connection to database
  • Alters input for safety
  • Creates SQL query
  • Displays the results
  • Close the connection to database

104
What is an Array?
PHP (and a Little MySQL) for the Default Library
Techie
An array is a variable that holds many different
variables in it.
An array of books.
105
result is an Array
PHP (and a Little MySQL) for the Default Library
Techie
where the results are stored.
resultmysql_query(query) or die("Couldnt
execute query.")
106
Mysql_fetch_array()
PHP (and a Little MySQL) for the Default Library
Techie
Use mysql_fetch_array() to gather the waiting
query results row by row, then display them.
counter0 while (rowsmysql_fetch_array(result
)) displaying data from results Display row
after row here with html.
107
Mysql_num_rows()
PHP (and a Little MySQL) for the Default Library
Techie
Use mysql_num_rows to get the number of matching
results. Numrows is the number of rows, or
records, in the result of the query.
numrowsmysql_num_rows(result)
108
Plan the Display
PHP (and a Little MySQL) for the Default Library
Techie
Write out how you want it to look!
  • There are X result(s) in your search.
  • lastname (maidenname), firstname middlename Born
    birthcity, birthstate
  • Died deathcity, deathstate
  • Obituary newspaper newsdate,
    newsyear

109
Display Results to User
PHP (and a Little MySQL) for the Default Library
Techie
counter0 numrowsmysql_num_rows(result) Prin
t "There are numrows result(s) in your
search."
110
Display Results to User
PHP (and a Little MySQL) for the Default Library
Techie
while (rowsmysql_fetch_array(result))
filling-in data from results countercounter1
Print counter.". ".rows"lastname". " (" .
rows"maidenname" ."), " . rows"firstname"
." " . rows"middlename"."
"
Red is HTML and the quotation marks surrounding
it.
111
Review of PHP
PHP (and a Little MySQL) for the Default Library
Techie
112
search.php
PHP (and a Little MySQL) for the Default Library
Techie
  • Creates connection to database
  • Alters input for safety
  • Creates SQL query
  • Displays the results
  • Close the connection to database

113
Close Connection
PHP (and a Little MySQL) for the Default Library
Techie
Mysql_close is the function to close the
connection to the server.
mysql_close(connection)
114
Exercise 6
PHP (and a Little MySQL) for the Default Library
Techie
Open up Notepad and get to coding!
115
Include Files Require Files
PHP (and a Little MySQL) for the Default Library
Techie
Include and require insert files (sensitive or
oft-repeated code stored in files) into the
current code. This will prove useful and
protective once you connect to a database, as
well as for other repeated functions.
Include "/path/to/filename.html" include
("footer.txt") require ("start.inc")
example17.inc
116
Include Files Require Files
PHP (and a Little MySQL) for the Default Library
Techie
The file start.inc might look like
.org" username"phpclass" password"infopeople
" database"obituaries" tablename"people" ?

example17.inc
117
Include File Placement
PHP (and a Little MySQL) for the Default Library
Techie
Define Connection Variables Require
("start.inc") Connect to Serve Database
connectionmysql_connect(hostaddress,
myusername, mypassword) or die ("Cant connect
to server.")
118
PHP Covered
PHP (and a Little MySQL) for the Default Library
Techie
print require() str_replace() strip_tags strtolowe
r() trim() while // / / . \
date() die() echo elseif if else include() mysql
_close() mysql_connect() mysql_fetch_array() mysql
_num_rows() mysql_query() mysql_select_db()
19 down, 4592 to go!
119
Evaluation Time
PHP (and a Little MySQL) for the Default Library
Techie
Please go to infopeople.org/wseval.html and
complete the evaluation.
Thank you!
Write a Comment
User Comments (0)
About PowerShow.com