[ Symbols ], [ Numbers ], [ A ], [ B ], [ C ], [ D ], [ E ], [ F ], [ G ], [ H ], [ I ], [ J ], [ L ], [ M ], [ N ], [ O ], [ P ], [ Q ], [ R ], [ S ], [ T ], [ U ], [ V ], [ W ], [ X ], [ Z ],
Symbols[ Top ]
& (ampersand)
&& (logical AND) operator, 68, 71
bitwise AND operator, 68
reference operator, setting a variable reference, 105
reference parameters, 91
< > (angle brackets)
< (less than) operator, 53, 68, 70
< > (not equal) operator, 53
<< (bitwise shift left) operator, 68
<= (less than or equal to) operator, 54, 68, 70
> (greater than) operator, 54, 68, 70
> (redirection) operator, 156
>= (greater than or equal to) operator, 54, 68, 70
>> (bitwise shift right) operator, 68
enclosing HTML tags, 11
PHP tags (<?php ?>), 368
* (asterisk)
multiplication assignment (*=) operator, 58
multiplication operator, 57, 68
zero or more matches in regular expressions, 331
@ (at sign), error control operator, 68
suppressing information about the database, 320
~ (bitwise NOT) operator, 68
\ (backslash), escaping quotes in strings, 52
^ (caret)
beginning-of-line matching in regular expressions, 331
bitwise NOR operator, 68
negating character classes in regular expressions, 332
: (colon)
:: (scope resolution) operator, 104
separating expressions in ? operator, 74
, (comma) CSV data format, 158
{ } (curly braces)
arrays referenced in string having whitespace or punctuation in key value, 111
enclosing statements in PHP, 73, 370
$ (dollar sign)
beginning PHP variables, 43
end-of-line matching in regular expressions, 331
= (equals sign)
= = (equality) operator, 53, 68, 69
= = = (identity) operator, 53, 68, 70
assignment operator, 44, 68, 69
! (exclamation mark)
!= (inequality) operator, 68, 70
!= (not equal) operator, 53
!== (nonidentity) operator, 68
logical NOT operator, 68
# (hash sign), in HTML and PHP comments, 24
- (minus sign)
- - (decrement) operator, 59, 68
-= (subtraction assignment) operator, 58
subtracting date and time values, 173
subtraction operator, 57, 68
unary minus operator, 68
-> operator, 104
( ) (parentheses)
calling functions, 87
changing operator precedence levels, 67
function call operator, 68
modifying preference for logical operators in WHERE clause, 140, 145
% (percent sign)
modulo operator, 57
modulus operator, 68
wildcard character in MySQL, 143
. (period)
.= (concatenation assignment) operator, 58
concatenation operator, 68
dot notation or property access operator, 68
string concatenation, 54
string concatenation operator, building query string, 185
+ (plus sign)
++ (increment) operator, 59
++(increment) operator, 68
+= addition assignment operator, 58
adding date and time values, 173
addition operator, 57, 68
one or more matches in regular expressions, 331
unary plus operator, 68
? (question mark)
? : (conditional) operator, 68, 74
zero or one matches in regular expressions, 331
" (quotes, double), escaping in strings, 52
' (quotes, single)
'/ and /', enclosing regular expressions, 332
in strings, 51
; (semicolon), ending PHP statements, 42, 63
/ (slash)
// for single-line and /* ... */ for multiline comments, 42
/= (division assignment) operator, 58
division operator, 57, 68
escaping in regular expressions, 332
[ ] (square brackets)
accessing items in an array, 111
array index operator, 68, 109
character classes in regular expressions, 332
surrounding optional function arguments, 89
_ (underscore)
separating multiple words in variable names, 44
wildcard character in MySQL, 144
| (vertical bar)
|| (logical OR) operator, 68, 71
bitwise OR operator, 68
Numbers[ Top ]
1NF (First Normal Form), 150
2NF (Second Normal Form), 152
3NF (Third Normal Form), 153
A[ Top ]
abbreviations, 369
abstraction, 179
PDO database abstraction layer, 372
$action variable, 355
action keyword, 199
Active Server Pages (ASP), 4
ADD column command, 137
addition (+) operator, 57
addition assignment (+=) operator, 58
addition, date and time arithmetic, 172
addslashes function, 322
AFTER keyword, 137
Ajax, 373
aliases for tables included in database query, 142
ALTER TABLE command, 136
anchors (regular expression), 331
AND (logical AND) operator, 68, 70
angle brackets (see < >, under Symbols)
answers to chapter questions, 377-389
Apache, 5
authentication, 288
access control for administrative scripts, 308
installing, 16-20
default index page after installation, 20
default installation directory, 18
downloading Apache 2.x Win32 MSI installer binary, 16
Installation Wizard, using, 16
on Linux, 16
testing your installation, 20
Web Server Setup dialog, 23
loading extensions, using modules, 5
restarting server after PHP installation, 25
telling to process PHP extensions as PHP files on Mac OS X, 26
versions, 5
arguments, operator, 63
arithmetic operators, 68
array function, 109
creating a multidimensional array, 115
array identifiers, 109
adding values to end of existing array, 112
array index operator ([ ]), 68
arrays, 107-121
associative vs. numeric indexed, 107
creating, 108
adding values to an array, 112
assignment via array construct, 109
assignment via array identifiers, 109
counting elements in an array, 112
looping through and referencing array values, 111
sorting arrays, 113
elements and indexes, 107
extracting variables from, 117-119
numeric array, 118
preventing overwriting a variable, 117
using compact to build an array from variables, 118
form checkbox with multiple values, 208
functions for, 119
multidimensional, 114-116
creating, 115
displaying, 115
results from query, 187
returned by form checkbox, 204
super globals defined in, 49
AS keyword, 142
ASP (Active Server Pages), 4
assignment
array values via array identifiers, 109
combined assignment operators, 58
values to variables, 44
assignment operators
PHP, 58
restrictions on lefthand operand, 66
associative arrays, 107
adding value to existing array, 112
creating (example), 110
example, 108
multidimensional, 114
query results, 187
associativity (operator), 69
assort( ) function, 113
attributes (database fields), 132
Auth PEAR module, 302
authentication
Apache authentication, restricting access to scripts, 308
Auth_HTTP PEAR module, using, 341-343
HTTP, PHP and, 288-294
storing login information in a database, 290-292
validating username and password, 290
verifying login information against database, 292
using Auth_HTTP PEAR module, 301-305
AuthOpts array, 303
AUTO_INCREMENT keyword, 133
auto_increment keyword
generating unique ID for a column, 155
using to assign IDs, caution with, 281
B[ Top ]
\B (nonword boundary) in regular expressions, 331
\b (word boundary) in regular expressions, 331
<b>, <tt>, and <i> elements, no longer supported in XHTML 2.0, 255
backing up database data, 155-159
best practices, 159
copying database files, 156
mysqldump command, 156-158
store database backup (example), 156
binary number, outputting with printf, 224
binary operators, 65
restrictions on lefthand operand, 66
bitwise NOT operator (~), 68
blog (example), 339-364
adding and changing comments, 358-364
adding and changing posts, 352-357
configuration file, 340
database, 343-346
page framework, 340-343
posting and its comments, displaying, 349-351
postings summary, displaying, 346-348
Booleans, 62
break statements, 76
breaking out of loops, 81
using continue instead of, 82
browsers (see web browsers)
bundled installations of Apache, MySQL, phpMyAdmin, and PHP, 16
C[ Top ]
CakePHP, 372
capitalize function (example), 90
default parameter, $each, 90
modifying to take a reference parameter, 91
Cartesian product, 138
Cascading Style Sheets (see CSS)
case
case-insensitive searches in MySQL, 143
case-insensitivity, PHP function names, 87
case-sensitivity in PHP variables, 44
changing for strings with PHP functions, 231
in regular expression pattern matching, 332
in string comparisons, 53
casting
converting data types, 65
PHP cast operators, listed, 68
variables, 66
categories table (blog example), 344
CGI (Common Gateway Interface), 1
chapter questions, answers to, 377-389
character classes (regular expression), 332
checkboxes (form), 204
using same name to store multiple values, 208-210
validating user input from, 210
checkdate function, 236
class scope, 99
classes, 96
constructors, 97
creating, 96
inheritance, 101-104
instances of, 96
instantiating, 98
new construct, using, 98
methods and constructors, 97
scope of variables within, 99
closing database connections, 187
code examples from this book, using, xi
columns or attributes (database fields), 132
columns, database
adding in MySQL, 137
changing data type in MySQL, 136
data types, 154-155
common MySQL types, 154
displaying from selected tables in MySQL, 138
indexes using more than one column, 161
referencing as TABLE.COLUMN in MySQL, 140
removing in MySQL, 138
renaming in MySQL, 137
result row columns, 186
combined assignment operators, 58
command line, accessing MySQL, 123-125
commands available at MySQL prompt, 124
MySQL prompts, 124
comma-separated values (CSV) format, 158
$comment_count variable, 350
comments
// for single-line and /* ... */ for multiline comments, 42
HTML and PHP, 24
PHP, 41, 366
file comments, 367
function comments, 367
comments (blog example), adding and changing, 358-364
comments table (blog example), 344
commit command, 177
Common Gateway Interface (CGI), 1
compact function, 118
comparison operators, 53
listed, with precedence level, operands, and associativity, 68
testing the relationship between two values, 70
compatibility, PHP application components, 7
CONCAT function, 165
CONCAT_WS function, 165
concatenation, 54
concatenation assignment (.=) operator, 58
concatenation operator (.), 68
conditionals, 71-77
? : operator, 74
formatting in PHP code, 370
if statement, 72-74
primary elements of, 71
switch statement, 75
config.php file (blog example), 340
configuration details for PHP, 25
Configuration Directory dialog (for Apache), 23
connect function, 195
connect string (PEAR DB), 195
constants, 55-56
naming, 369
predefined, 56
constraints, 6
_ _constructor function, 97
constructors, 97
calling constructor of parent class for an extended class, 103
for class instances, 98
creating, PHP 5 syntax for, 97
continue statements, 82
control structures, formatting, 370
conversion specification, 224
$_COOKIE environment variable, 287
cookies, 285-288
accessing, 287
client browser and server interaction with, 285
destroying, 288
information sent in cross-site scripting attack, 322
session cookies blocked by user's browser, 286
session IDs stored in, 294
setting, 286
as user data, 319
copy function, 242
CREATE DATABASE command, 126
create statement, 264
CREATE TABLE command
specifying indexes, 160
create table command, 133
cross-site scripting attacks, 274
CSS (Cascading Style Sheets), 7, 10
Ajax, 373
controlling browser-based presentation in XHTML, 254
CSV (comma-separated values) format, 158
CURDATE function, 174
currency formats, printf function, 228
CURRENT_DATE function, 174
CURRENT_TIME function, 174
CURRENT_TIMESTAMP function, 174
cursors, 6
CURTIME function, 174
D[ Top ]
\D (nondigit character) in regular expressions, 331
\d (digit character) in regular expressions, 331
data structures (in databases), 131
data types
changing for column in MySQL database, 136
column, 154-155
common MySQL types, 154
dates and times, used in database functions, 172
defined, 154
operands, 65
variables, 45
converting to required type, 45
database abstraction
PDO, 372
PEAR DB classes, 179
database commands (MySQL), 124
database engines, 6
database functions, 164-178
date and time functions, 170-177
date and time arithmetic, 172-175
days, weeks, months, and years, 170-172
formatting dates for display, 175-176
hours, minutes, and seconds, 172
Unix timestamp conversion, 176
PHP, 179
string functions, 164-169
CONCAT, 165
CONCAT_WS, 165
cutting strings into substrings, 168
database functions (continued)
LENGTH, 166
location and position of strings, 168
search and replace, 169
trimming and padding strings, 166
UCASE and LCASE, 166
database triggers, 6
databases, 4
backing up and restoring data, 155-159
backup best practices, 159
copying database files, 156
mysqldump command, 156-158
mysqlimport command, 159
blog (example), 343-346
creating, 344
inserting sample data, 345
concepts, 131-132
record and fields, 132
date and time functions, 170
design, 146-155
column data types, 154-155
forms of normalization, 150-154
normalization, 149
relational databases, 146
relationship types, 147-148
MySQL, 6
preventing access to, 320
for external hosts, 321
relational, 132
schema, 6
separate users in MySQL for each application, 321
string functions, 164
transactions, 177
(see also MySQL)
date function, 233
DATE_ADD function, 172
DATE_FORMAT function, 175-176
DATE_SUB function, 172
dates and times, 154
database functions, 170-177
date and time arithmetic, 172-175
days, weeks, months, and years, 170-172
formatting dates for display, 175-176
hours, minutes, and seconds, 172
Unix timestamp conversion, 176
PHP functions for, 233-237
arithmetic, 235
display formats, 234
timestamp creation with mktime, 237
validating dates with checkdate, 236
DAYNAME function, 171
DAYOFMONTH function, 171
DAYOFWEEK function, 170
DAYOFYEAR function, 171
DB class, 195
connect method, 195
query method, 195
DB::errorMessage function, 196
DB::isError function, 196
debugging
array values, 116
PHP code, tools for, 116
decrement operator (- -), 68
default installation directory, Apache, 18
default values in function parameters, 90
DEFAULT: statement, using with switch statement, 76
DELETE command, 143, 277
describe (desc) command, 264
DESCRIBE command, 134, 161
destination folder, PHP installation, 22
developing locally, 15
DevPHP, 39
df command, 249
dimensions (multidimensional arrays), 114
directory.html file, 12
DirectoryIndex directive (Mac OS X), mapping PHP index files to, 26
disconnect function, 196
display_errors parameter, 336
division (/) operator, 57
division assignment (/=) operator, 58
do ... while loops, 79
Document Object Model (DOM)
Ajax, 373
events, 255
Document Type Definitions (DTDs), declarations in XHTML, 256
dollar sign ($), beginning PHP variable names, 43
DOM (Document Object Model)
Ajax, 373
events, 255
dot notation (.) operator, 68
DROP command, 138, 265
DTDs (Document Type Definitions), declarations in XHTML, 256
duplication of data, minimizing, 149
dynamic web development, online resources, xi
dynamic web pages, 1
components necessary for, 4-7
database, MySQL, 6
server-side programming language, PHP, 4
web server, Apache, 5
E[ Top ]
each( ) function, 115
echo function, 86
echo( ) function, 40
elements
acting as hyperlinks, XHTML 2.0, 255
array, 107
counting, 112
scalar values, 108
HTML, 11
else statement, 73
email address, regular expression describing, 330
ENCLOSED BY char, 159
encoding passwords, 311
encrypting passwords, 311
endswitch, using to end switch statement, 77
enterprise databases, 7
equality (= =) operator, 53, 68, 69
ereg-style regular expressions, 329
error control operator (@), 320
error levels, 337
error logging (PHP), 336
error_log parameter, 337
error_reporting parameter, 337
errorMessage function, 196
errors
common pitfalls in XHTML code, 258
connection to database, 184
database, handling from PHP, 265
displaying from PHP and redisplaying form, 333-336
generating using switch and DEFAULT: statements, 76
inhibiting (@ operator), 68
PEAR error reporting, 196
escaped characters, 51
escapeshellcmd function, 249
escapeSimple function (PEAR), 274
escaping user input, 319, 322
events (DOM), replaced by XML Events in XHTML 2.0, 255
example code from this book, using, xi
exec function, 249
existence of a function, checking for, 95
expand function, 117
expiration date (cookies), 288
EXPLAIN command, 162
expressions, 62-64
combining with operators into more complex expressions, 63
defined, 62
formatting in PHP, 368
literals and variables, 62
valid expressions (examples), 62
extends operator, 101
extensions, loading into Apache, 5
extract function, 117
EXTR_PREFIX_ALL option, 118
F[ Top ]
feet-to-meters converter (in PHP), 212
Fetch (FTP client), 36
fetchRow function, 196
file comments (PHP), 367
file manipulation functions, PHP, 238-248
checking permissions, 239
creating files, 240
deleting files with unlink command, 241
file_exists function, 239
rename function, 242
uploading files, 243-248
accessing the file, 244
is_uploaded_file function, 244
move_uploaded_file function, 246
validation, 244-248
URL wrappers, 242
file_exists function, using with touch and unlink commands, 241
file_get_contents function, 242
$_FILES global array, 244
files
include files, 310
including and requiring PHP files, 370
verifying integrity of with md5 function, 88
Fink, downloading and installing, 33
firewall setup utilities, 321
FIRST keyword, 137
First Normal Form (1NF), 150
fopen function, 242
for loops, 80
foreach loop, displaying contents of an array, 111
foreign key relationship, 146
foreign keys, 6
formatting standards (PHP), 367, 368
expressions, 368
function definitions, 369
indenting, 368
PHP tags, 368
templating, 368
formatting string (printf), 224
forms, 199-222
accessing submitted values, 201
building, 199-200, 212
basic form components, 199
simple form (example), 200
checkboxes using same name to store multiple values, 208-210
database queries using form data, 215-217
default values, specifying, 202
feet-to-meters converter in PHP, 212
input types, 203-207
checkboxes, 204
hidden elements, 206
radio buttons, 205
selects, 206
text areas, 204
text boxes, 203
input, using to add data to database table, 270-276
SQL injection, preventing, 273
post form template, 357
prompting for file upload, 243
redisplaying after PHP validation failure, 333-336
templates, 218-222
time zone conversion utility in PHP, 212-215
user_id, 350
validating user data, 210-212
from checkboxes, radio buttons, and selects, 210
from text boxes and text areas, 211
validating user input with JavaScript, 325-329
XForms in XHTML 2.0, 255
frames, XFrames in XHTML 2.0, 255
frameworks (PHP), 372
from_unixtime( ) function, 176
FTP account, activating at your ISP, 35
FTP clients, 36
FTP Voyager, 36
full installations, 16
function call operator (( )), 68
function calls, 368
function comments (PHP), 367
function statement, 89
function_exists function, 95
functions, 45, 85-106
array, 119
array function, 109
built-in, 85
calling, 87
database, 164-178
date and time functions, 170-177
string functions, 164-169
date and time functions in PHP, 233-237
defined, 85
defining in PHP, 369
defining your own, 89-95
hi function (example), 89
including and requiring PHP files, 92-95
parameter references, 91
parameters, 89
testing a function, 95
formatting function calls in PHP, 368
grouping data, 164
mathematical, 57
naming, 369
object-oriented programming (OOP), 96-105
parameters, 86
return values, 87
string comparison, 52
string functions, 223
(see also methods)
G[ Top ]
garbage collection, 299
PHP .ini variables for, 300
GET operations, data from, 318
get_magic_quotes_gpc function, 323
global variables, 46
automatic, security risks, 312-316
naming, 369
super globals, 49
Google Maps, 373
grant command (MySQL), 125
greater than (>) operator, 54
greater than or equal to (>=) operator, 54
grep-style regular expressions, 329
GROUP BY clause, using with SELECT statement, 164
grouping functions, 164
H[ Top ]
hashcheck function, 87
heading element <h> in XHTML 2.0, 255
Hello world! program (example), 86
hidden form elements, 206
HOUR function, 172
.htaccess file, 300
securing directories containing administrative scripts, 308
HTML
CSS, controlling appearance of pages, 10
directory.html file, 12
markup, 11
PHP and, 39-43
text output, 39-43
PHP templates and, 7
separating from PHP processing code, 218
HTML forms (see forms)
htmlentities function, 274
escaping special characters, 319
htpasswd command, 309
HTTP, 1
default port, 18
TCP/IP, 2
HTTP authentication, 288-294
storing login information in a database, 290-292
using with a PHP script, 289
validating username and password, 290
verifying login information against database, 292
$HTTP_POST_FILES array, 244
hyperlinks (see links)
I[ Top ]
<i>, <b>, and <tt> elements, no longer supported in XHTML 2.0, 255
IDE (Integrated Development Environment), 116
identifiers, array, 109
identity (= = =) operator, 53, 68, 70
if statement, 72-74
else statement, 73
syntax, 73
testing a variable for multiple values, switch statement vs., 75
true conditions, 72
IIS (Internet Information Services), 5
img elements in XHTML 2.0, 255
implicit casting, 65
importing data from another database, 159
include files, 310
include function
handling of missing files, 310
include statement, 92
problems with, 94
include_once statement, 93
problems with, 94
include_path function, 242
including files, 370
increment operator (++), 68
incrementing/decrementing
autoincrement and autodecrement, 59
preincrement -decrement, 59
indenting (PHP code), 368
index files (PHP), mapping on Mac OS X 10.2 to DirectoryIndex, 26
indexes
array, 107
numeric indexed arrays, 107
query results, 187
specifying, 109
supplied by PHP, 109
database, 159-163
EXPLAIN command, 162
multicolumn indexes, 161
when to use, 160
where to specify, 160
MySQL database, 134
infinite loops, 78
information from many sources, integrating, 7-11
CSS (Cascading Style Sheets), 10
PHP templates, 8
inheritance in OOP, 101-104
ini_set function, 319
initializing variables for improved security, 316
input types, form, 203-207
checkboxes, 204
hidden form elements, 206
radio buttons, 205
selects, 206
text areas, 204
text boxes, 203
INSERT command, 135, 345
INSERT statement, using in PHP script, 266
insert_db function, 272
install path for Apache, 23
installation
Apache, 16-20
developing locally, 15
Fink, 33
MySQL, 27-33
PHP, 21-27
working remotely, 35
XAMPP, 33-35
instances (class), 96
creating, 97
Integrated Development Environment (IDE), 116
Internet Server Application Program Interface (ISAPI), 5
Internet, HTTP and, 1
interpreter, PHP, 13
IP address, in session information, 317
is_array, 110
is_executable function, 239
is_readable function, 239
is_uploaded_file function, 244
is_writable function, 239
ISAPI (Internet Server Application Program Interface), 5
isError function, 196
ISPs
PEAR DB, 192
transferring files and directories to, 35
iterations, loops, 77
J[ Top ]
JavaScript
in Ajax, 373
code in cross-site scripting attack, 321
validating user data, 325-329
regular expressions, 326
joins
JOIN ON keyword, 142
LEFT JOIN ON clause, using with SELECT, 163
natural joins, 141
natural joins in SELECT, 343
JSP (Java Server Pages), 4
L[ Top ]
LCASE and UCASE functions, 166
leading spaces or characters, trimming from strings, 167
LEFT function, 168
LEFT JOIN ON clause, 163
LENGTH function, 166
length of a string (strlen), 230
Lerdorf, Rasmus, 4
less than (<) operator, 53
less than or equal to (<=) operator, 54
LIKE keyword, 143
links
deleting current row in a database, 277
displaying database query results with embedded links, 267-270
elements in XHTML 2.0, 255
Linux
installing Apache, PHP, and MySQL, 16
MySQL datafiles directory, 156
phpMyAdmin configuration file, 126
literals, 62
regular expression, 330
LOCATE function, 168
logical AND operator, 68
logical NOT operator (!), 68
logical operators, 70
logical statements and their results, 71
using in WHERE clause, 140, 144
logical OR operator, 68
logical XOR operator, 68
logically grouping related data, 150
login settings for MySQL, 181
login systems, use of session variables, 297
login.php file, 13
loops, 77-83
breaking out of, 81
continue statements, using, 82
do ... while, 79
for loops, 80
infinite, 78
iterations, 77
looping through array items and referencing array values, 111
while loops, 78
LPAD and RPAD functions, 166
LTRIM and RTRIM functions, 167
M[ Top ]
Mac OS X
accessing MySQL with command line, 123
Apache, 16
enabling PHP, 25
MySQL datafiles directory, 156
MySQL installation, 33
magic quotes, 322
checking whether it's enabled, 323
escaping user input, 273
many-to-many relationships (database), 148
math, 57-60
autoincrement and autodecrement, 59
basic operators, 57
combined assignment operations, 58
preincrement and -decrement, 59
mathematical operations, 57
mathematical operators, types of operands, 65
MAX clause, using an index, 160
MAXLENGTH attribute, setting in form text fields, 326
md5 function, 87
md5 one-way encrypt function, 311
MDB2 (PEAR database interface), 196
message digest, 87
metacharacters (regular expression), 330
quantifiers, 331
method keyword, 199
methods, 96, 97
static, 104
Microsoft
Active Server Pages (ASP), 4
Windows (see Windows)
MIME type, setting for XHTML documents, 262
MIN clause, using an index, 160
minimized attributes (HTML), 260
MINUTE function, 172
mirrors (download locations), 16
mktime function, 237
MODIFY command, 137
modules
Apache, 5
online source, 5
PEAR, categories of, 190
PHP, uncommenting line that loads on Mac OS X, 26
modulo (%) operator, 57
MONTH function, 171
MONTHNAME function, 171
move_uploaded_file function, 246
multicolumn indexes, 161
multidimensional arrays, 114-116
creating, 115
displaying, 115
multiline comments, 42
multiplication (*) operator, 57
multiplication assignment (*=) operator, 58
MySQL, 122-145
accessing the database with the command line, 123-125
commands available at MySQL prompt, 124
MySQL prompts, 124
administering with phpMyAdmin, 126-129
common data types, 154
connecting to database from PHP, 180
connecting to the database, 122
data types, online listing of types, 155
database concepts, 131-132
database engines, 6
database objects, changing from PHP, 263-265
creating a table, 263-265
dropping a table, 265
handling errors, 265
development history, 6
major releases and features, 6
functions, using, 164-178
installing, 27-33
Mac OS X installation, 33
on Linux, 16
PHP Connector, 32
managing the database, 125
creating a database, 126
creating users, 125
manipulating data from PHP, 266
deleting data, 277-281
displaying results with embedded links, 267-270
form to add data to a table, 270-276
performing a subquery, 282-284
updating data, 276
place in web development, 2
preventing access to the database, 320
for external hosts, 321
relational database, 146
separate database users for each application, 321
SQL (Structured Query Language), 132-145
adding data to a table, 135
creating tables, 133
deleting database data, 143
logical operators in WHERE clause, 144
modifying database data, 142
querying the database, 138-142
search functions, 143
table definition, manipulating, 136-138
using with PHP, advantages of, 3
(see also databases)
MySQL Server Instance Configuration Wizard, 29
MYSQL_ASSOC fetch type, 187, 190
mysql_close function, 187
mysql_connect function, 184
database connection, 185
mysql_error function, 184
mysql_fetch_array function, 187
mysql_fetch_assoc function, 187
mysql_fetch_row function, 186
mysql_insert_id( ) command, 280
MYSQL_NUM fetch type, 187
mysql_query function, 186
mysql_real_escape_string command, 319
mysql_real_escape_string function, 273
mysql_select_db command, 185
mysqldump command, 156-158
--all-databases switch, 157
backing up a single table from a database, 157
backing up store database (example), 156
CSV data format, 158
--no-create-info switch, 158
--no-data switch, 158
output file contents, 157
redirecting output to a file, 156
restoring a database backup, 158
syntax, 156
mysqlimport command, 159
N[ Top ]
\n (newline character) in regular expressions, 331
namespaces, XML, 254
naming guidelines, 369
NATURAL JOIN keyword, 141
negated character class, 332
nested menus in XHTML, 255
new operator, 98
nextId function, 280
nl element, 255
normalization, 149
forms of, 150-154
First Normal Form (1NF), 150
Second Normal Form (2NF), 152
Third Normal Form (3NF), 153
NOT (logical NOT) operator, 70
not equal (!=) operator, 53
not equal (< >) operator, 53
NOT NULL keyword, 133
Notepad, 39
NOW function, 174
number of matches in regular expressions, 331
numbers, 154
numeric arrays
extract function, using with EXTR_PREFIX_ALL, 118
query results, 187
numeric indexed arrays, 107
creating (example), 109
numRows function, 283
O[ Top ]
object-oriented programming (OOP), 96-105
classes, 96
creating a class, 96
creating a class instance, 97
inheritance, 101-104
methods and constructors, 97
static methods and variables, 104
variable references, 105
variable scope within classes, 99
objects, 369
creating a new object and assigning it to a variable, 99
in object-oriented programming, 96
off-by-one error (array indexes), 107
one-to-many relationships (database), 148
one-to-one relationships (database), 147
online resources for dynamic web development, xi
OOP (see object-oriented programming)
open source, value of, 3
operands, 63
operating systems (OS)
connecting to MySQL, 123
support by PHP and MySQL, 7
operators, 64-71
& (reference) operator, setting a variable reference, 105
-> operator, 104
arguments, 63
associativity, 69
autoincrement and autodecrement, 59
combined assignment, 58
combining simple expressions into more complex, 63
defined, 62
equality, 69
extends operator, 101
mathematical, 57
new operator, 98
number of operands, 65
operands, 63
order of precedence, 67
overloaded, 63
parent operator, 102
PHP
categories of, 64
listed, with order of precedence, 67
online listing, 64
relational, 69-71
scope resolution (::) operator, 104
types of operands, 65
OR (logical OR) operator, 68, 70
ORDER BY clause
SELECT statement, 138, 140
using an index, 160
ORDER BY statement, 347
order of precedence (operators), 67
listing for PHP operators, 68
origin server, 2
OS (operating systems)
connecting to MySQL, 123
support by PHP and MySQL, 7
overloading operators, 63
P[ Top ]
padding strings, 166
printf function (PHP), 226-228
parameters (constructor methods), 98
parameters (function), 86, 89
default values in, 90
parameter references, 91
parent operator, 102
partitioning, 6
passwords
storing in the database, 311
pattern matching, 329
(see also regular expressions)
PCRE (Perl-compatible regular expressions), 329
PDO database abstraction, 372
PEAR (PHP Extension and Application Repository), 190-197, 371
adding packages, 192
Auth_HTTP, 301-305, 341-343
categories of modules, 190
creating connection instance with PEAR DB, 195
database functions, 179
displaying books table (example) with PEAR DB, 193
displaying books table (example) with PEAR::MDB2, 196
installing PEAR, 191-192
structured libraries, 371
pear install Auth command, 302
pear install Auth_HTTP command, 302
PEAR::MDB2, 196
PECL (PHP Extension Community Library), 371
Perl-compatible regular expressions (PCRE), 329
permissions
checking for files, 239
directories containing session data, 320
PHP, 39-61
accessing files remotely, 37
application components, 4-7
Apache web server, 5
compatibility of, 7
MySQL, 6
MySQL database, 6
PHP, 4
arrays, 107-121
array functions, 119
blog postings summary, displaying, 346-348
changing database objects from, 263-265
creating a table, 263-265
dropping a table, 265
handling errors, 265
code building blocks, 43-60
concatenation, 54
constants, 55-56
PHP (continued)
math, 57-60
strings, 50-54
variables, 43-50
coding standards, 366-370
comments, 366
control structures, 370
formatting, 367
naming guidelines, 369
objects, 369
COM, 4
comments, adding/changing (blog example), 358-364
conditionals, 71-77
connecting to MySQL database, 180, 183
database functions, 179
date and time functions, 233-237
arithmetic, 235
display formats, 234
timestamp creation with mktime, 237
validating dates with checkdate, 236
enabling on Mac OS X, 25
testing your installation, 27
error logging, 336
expressions, 62-64
file manipulation functions, 238-248
forms
database query using form data, 215-217
feet-to-meters converter, 212
file handling submission of form data, 200
modifying search to process results, 201
time zone conversion utility, 212-215
frameworks, 372
functions, 45, 85-106
generating XHTML, 261
HTML text and, 39-43
adding PHP comments, 42
text output, 39-43
HTTP authentication, 288-294
validating username and password, 290
verifying username/password against database, 292
installing, 21-27
destination folder, 22
downloading latest version, 21
Installation Wizard, using, 21
on Linux, 16
restarting Apache server, 25
testing your installation, 25
manipulating database data, 266
deleting data, 277-281
displaying results with embedded links, 267-270
form to add data and process, 270-276
inserting comment into database table, 7
performing a subquery, 282-284
updating data, 276
MySQL PHP Connector, installing, 32
operators, 64-71
PEAR (see PEAR)
place in web development, 2
posting and its comments, displaying (blog example), 349-351
posts, adding and changing (blog example), 352-357
regular expressions, 332
selecting database to query, 185
separating from HTML presentation code, 218
server-side processing, 11
sessions, 294-301
.ini variables dealing with garbage collector, 300
ending, 298-301
storing in database, 301
user authentication, checking, 297
using, 295
string functions, 223-233
changing case, 231
checking for a string with strstr, 232
extracting portion of a string, 232
formatting strings for display, 224-230
length of a string, 230
system calls, calling, 249
templates, 8
sample script, 219
Smarty template engine, 9
using template to display a table, 221
using with MySQL, advantages of, 3
validation failure, redisplaying form after, 333-336
variable references, 105
XSL, 4
<?php and ?> tags, surrounding code with, 40
phpinfo function, 87
phpMyAdmin, 126-129
authentication for MySQL, 127
configuration file, 126
defining connection details for MySQL server, 127
graphical interface, 129
installing, 126
login for MySQL, 127
objects in test database and author's table structure, 129
selecting database to administer, 128
plug-in API, 6
pointers, 119
port numbers, 321
default HTTP port, 18
position in a string, finding for a substring, 233
POST operations, data from, 318
$post_id, 355
postincrement and -decrement, 60
posting and its comments, displaying (blog example), 349-351
postings summary, displaying (blog example), 346-348
posts table (blog example), 344
posts, adding and changing (blog example), 352-357
precedence, operators, 67
PHP operators listed with precedence level, 68
predefined constants (PHP), 56
preg_ functions, 332
preg_match function, 333
preincrement and -decrement, 59
primary key, 146
importance in updates and deletions, 276
PRIMARY KEY keyword, 133
print construct, 40
printf function, 224-229
decimal point precision for numbers, 228
displaying same number in different formats, 225
formatting string, 224
padding strings, 226-228
property access operator (.), 68
property and about attributes, RDF support in XHTML 2.0, 255
Q[ Top ]
quantifiers (regular expression), 331
query function, 195
querying the database
basic steps in process, 180
building SQL SELECT query, 185
closing the connection, 187
connecting to MySQL database, resources for, 180
fetching and displaying results, 186
having database execute the query, 186
PEAR functions, using, 190-197
PHP functions, using, 180-190
putting it all together (example), 187-190
unions, 6
using form data, 215-217
quotation marks
in data for MySQL database tables, 135
magic quotes (see magic quotes)
in strings, 51
R[ Top ]
\r (carriage return) in regular expressions, 331
radio buttons (form), 205
setting up, 210
validating user input from, 210
RDBMS (Relational Database Management System), 6
realm for HTTP authentication, setting, 303
records (database), 132
redirection operator (>), 156
reference operator (&), 105
reference parameters, 91
references, variable, 105
register_globals setting, 312
reading session variables from, 314
regular expressions, 326, 329-333
anchors, 331
character classes, 332
ereg, 329
executing in PHP, 332
literals, 330
metacharacters, 330
Perl format, 332
Perl-compatible, 329
quantifiers, 331
syntax (example), 330
Relational Database Management System (RDBMS), 6
relational databases, 6, 146
MySQL, 6
relational operators, 69-71
comparison operators, 70
logical operators, 70
testing for equality or identity, 69
relationships, database, 147-148
many-to-many, 148
one-to-many, 148
one-to-one, 147
remote web server, working from, 35
RENAME command, 136
rename function, 242
REPLACE function, 169
$_REQUEST super global, 315
require function, 92
handling of missing files, 310
require statement, 94
require_once function, 92
require_once statement, 94
requiring files, 370
Resource Description Framework (RDF), support in XHTML 2.0, 255
resources
used in connecting to MySQL database, 180
web, 366, 373
restoring MySQL backup, 158
result sets, 186
RIGHT function, 168
root username (MySQL), 123
row-based replication, 6
rows (database), fetching from the result set, 186
RPAD and LPAD functions, 166
RTRIM and LTRIM functions, 167
Ruby markup support (XHTML 1.1), 254
S[ Top ]
\S (nonwhitespace character) in regular expressions, 332
\s (whitespace character) in regular expressions, 331
scalar values, 108
scheduling, 6
schema (database), 6
scope resolution operator (::), 104
scope, variables, 45
within classes, 99
search and replace (MySQL database), REPLACE function, 169
search functions (MySQL), 143
SECOND function, 172
Second Normal Form (2NF), 152
section keyword, 222
secure hash algorithm (sha1), 311
security, 307-324
automatic global variables, 312-316
include files, 310
limiting access to administrative pages, 307
session, 316-324
checking for session hijacking, 316
creating separate database users, 321
cross-site scripting (XSS), 321
preventing access to the database, 320
preventing database access for external hosts, 321
shared hosting, 319
trusting user data, 318
SQL Injection, 217
storing passwords in the database, 311
user input form data process by a database
SQL injection attacks, 273
user input form data processed by database
cross-site scripting attacks, 274
SELECT *, 139
SELECT statement, 138
GROUP BY clause, 164
guarding against erroneous selections, 277
LEFT JOIN ON clause, 163
natural joins, 343
ORDER BY clause, 140
previewing data for deletion, 278
querying more than one table at a time, 140
WHERE clause, 139
selects (form input), 206
validating user input from, 210
serialized session variables, 294
$_SERVER super global
HTTP_Cookie, 288
trustworthiness of, 319
servers, interaction with cookies, 285
server-side processing, 11
server-side programming language, 4
$_SESSION global variable, 315
clearing, 299
registering variable by inclusion in, 296
session data, trustworthiness of, 319
session fixation, 316
session hijacking, 316
checking for, 316
session identifier, 294
session.gc_divisor variable, 300
session.gc_maxlifetime variable, 300
session.gc_probability variable, 300
session.save_path configuration parameter, 319
session_destroy function, 298
session_register function, 295
session_set_save_handler function, 301
session_start function, 295
sessions, 294-301
blog (example), 347
cookies, 286
ending, 298-301
garbage collection, 299
setting timeout, 300
login systems using session variables, 297
security, 316-324
$_SESSION super global, 315
creating separate database users, 321
cross-site scripting (XSS), 321
preventing access to the database, 320
preventing database access for external hosts, 321
register_globals and, 314
shared hosting, 319
trusting user data, 318
storage on the server, 294
storing in database, 301
using, 295
SET command, 142
set variable, 73
setcookie function, 286
destroying cookies, 288
parameter values and their meanings, 286
setRealm method, 303
settype operator, 65
sha1 (secure hash algorithm), 311
shared hosting, security concerns, 319
single-line comments, 42
size of a file, validating, 245
Smarty template engine, 9, 368
creating sample template, 220-222
escaping HTML, 357
installing, 218
application level directories, 219
creating sample PHP scripts, 219
online documentation for templates, 346
path to files, 340
software compatibility, OS for web server or client, 7
sort( ) function, 113
valid sort_flags for, 113
special characters in strings, 51
escaping, 52
special characters, escaping in user input, 322
sprintf function, 229
SQL (Structured Query Language), 132-145
adding data to a table, 135
rules for handling data using SQL commands, 135
building SELECT query, 185
creating tables, 133
deleting database data, 143
functions, 164-178
logical operators in WHERE clause, 144
manipulating table definitions, 136-138
adding a column, 137
changing column data type, 136
deleting an entire table, 138
removing a column, 138
renaming a column, 137
renaming a table, 136
modifying database data, 142
querying the database, 138-142
aliases for tables included in query, 142
join on, 142
joining tables together, 140
liming results with WHERE, 139
natural joins of tables, 141
specifying order of results, 140
relational databases and, 6
search functions, 143
SQL injection, 217
input data from a form submitted for database processing, 273
src attribute, referencing alternative media in XHTML 2.0, 255
SSH (Secure Shell), 2
start transaction command, 177
statements
conditional, 71-77
? : operator, 74
if statement, 72-74
switch statement, 75
defined, 62
statements (continued)
expressions and operators combined to form, 63
include statement, 92
include_once statement, 93
loops, 77-83
breaking out of, 81
do ... while loops, 79
for loops, 80
while loops, 78
loopscontinue statement, using instead of break, 82
require and require_once statements, 94
static methods and variables (in a class), 104
static variables, 47
static web pages, 1
HTML file, directory.html, 12
stored procedures, 6
strcasecmp function, 53
strcmp function, 53
string functions, 223
strings, 50-54, 154
capitalization functions, using, 90
comparing, 52
concatenating, 54
combining with another data type, 55
database functions, 164-169
CONCAT, 165
CONCAT_WS, 165
cutting strings into substrings, 168
LENGTH, 166
search and replace, 169
string location and position, 168
trimming and padding strings, 166
UCASE and LCASE, 166
length, 230
pattern matching (see regular expressions)
PHP functions, 223-233
changing case, 231
checking for a string with strstr, 232
extracting portion of a string, 232
formatting strings for display, 224-230
length of a string (strlen), 230
query string, building, 185
special characters in, 51
strlen function, 230, 233
strpos function, 233
strstr function, 232
strtolower function, 90, 231
strtoupper function, 231
structured information (in databases), 131
subclasses, 101
subqueries, 6
substr function, 233
SUBSTRING function, 168
substring functions (MySQL), 168
subtraction (-) operator, 57
subtraction assignment (-=) operator, 58
subtraction, date and time arithmetic, 172
Sun's Java Server Pages (JSP), 4
superclass, 101
switch statement, 75
break statements, 76
endswitch, using to end switch definition, 77
testing a variable for several values, if statement vs., 75
using DEFAULT: statement to generate an error, 76
SYSDATE function, 174
system calls, 249
system data, user data vs., 318
system date and time, 174
T[ Top ]
\t (tab character) in regular expressions, 332
TABLE.COLUMN, referencing MySQL columns, 140
tables, MySQL database
adding data to, 135
aliases for tables included in a query, 142
creating, 133
creating from PHP, 263-265
deleting entire table with TRUNCATE TABLE, 277
dropping from PHP, 265
joining, 140
manipulating table definition, 136-138
adding a column, 137
changing a column's database, 136
deleting entire table, 138
removing a column, 138
renaming a column, 137
renaming a table, 136
selecting which to query and which rows to view, 138
updating data, 142
tags, HTML, 11
elements, 11
tags, PHP, 368
TCP/IP, 2
port number for MySQL, 321
templates, 218-222, 368
blog page framework, 340-343
comment_form.tpl (blog example), 362
online documentation for Smarty templates, 346
PHP, 8
post_form.tpl, 357
posting summary display (blog example), 346-348
template engine, 218
installing Smarty, 218
temporary directory, session data stored in, 319
Terminal (Mac OS X), accessing PHP configuration file, 25
ternary operators, 65
? : (conditional) operator, 74
test_this function (example), 95
text areas (form), 204
validating user input from, 211
text boxes (form), 203
validating user input from, 211
text editors
creating PHP file, 25
writing PHP code, 39
text fields (form), MAXLENGTH attribute, 326
Third Normal Form (3NF), 153
this -> operator, 104
accessing a class variable, 100
threading, Apache support of, 5
time function, 233
time zone conversion utility (in PHP), 212-215
timeouts, setting for sessions, 300
timestamps
creating with mktime function, 237
date and time arithmetic with, 235
PHP functions, 233
timestamps, converting between Unix and MySQL, 176
token in URLs, stored as session variable, 317
touch command, 240
using with file_exists and unlink, 241
trailing spaces or characters, trimming from strings, 167
transactions, 177
triggers (database), 6
TRIM function, 167
trimming spaces or tabs from strings, 167
true conditions (if statement), 72
TRUNCATE TABLE command, 277
<tt>, <i>, and <b> elements, no longer supported in XHTML 2.0, 255
type specifiers, 224
for numbers, 225
U[ Top ]
UCASE and LCASE functions, 166
ucwords function, 231
unary operators, 65
uncommenting line that loads PHP module (on Mac OS X), 26
underscore (_) separating multiple words in variable names, 44
unions, 6
UNIQUE command, 160
unique identifiers
generating, 280
Unix
accessing MySQL with command line, 123
MySQL datafiles directory, 156
PEAR Package Manager, installing, 191
timestamps, PHP functions for, 233
unix_timestamp( ) function, 176
unlink command, 241
unnamed views, 6
UPDATE command, 142
WHERE clause, 142
updating database data from PHP, 276
uploading files, 243-248
accessing the file, 244
move_uploaded_file function, 246
validation, 244-248
checking existence of uploaded file, 244
checking file size, 245
checking file type, 245
URIs
XML namespaces, 254
URLs
wrappers used with filesystem functions, 242
USE command (MySQL), 125
user agent, 2
user data
validating with JavaScript, 325-329
validating with regular expressions, 329-333
user data, trusting, 318
user groups, 374
$user_id, 355
user_id session variable, 297
$username_id session variable, 347
users table (blog example), 345
users, creating for MySQL database, 125
V[ Top ]
validation, 325-329
dates, 235
files for upload, 244
PHP validation failure, redisplaying form after, 333-336
user input with regular expressions, 329-333
user input, validating with JavaScript, 325-329
XHTML documents, 257-258
variable poisoning, detecting, 315
variables, 43-50
assigning objects to, 99
assigning values to, 44
new value assigned to existing variable, 44
assignment to sessions, 295
casting, 66
in classes, 96
converting types, 65
creating, 44
data types, 45
converting to required type, 45
defining in PHP, 43
determining if an array, 110
expressions, 62
extracting from an array, 117-119
numeric array, 118
preventing overwriting a variable, 117
using compact to build an array from variables, 118
global, 46
initializing, 316
naming, 43, 369
reading value of, 44
references, 105
scope, 45
within classes, 99
security risks of automatic global variables, 312-316
serialized, 294
set, 73
static, 47
static class variables, 104
string, 50
super globals, 49
Voyager (FTP client), 36
W[ Top ]
\W (nonword character) in regular expressions, 332
\w (word character) in regular expressions, 332
web applications (blog example), 339-364
web browsers
compatibility with XHTML, 261
cookies, 285
JavaScript, 325
operating systems and, 7
session IDs, 294
session information about, 317
XHTML and, 253
web pages
dynamic, 1
main components of, 4-7
requesting data from, 11-13
PHP interpreter, MySQL and web server cooperating, 13
static, 1
web server process, 12
Web Server Setup dialog (for Apache), 23
web servers, 2, 4
accessing PHP files through, 37
Apache, 5
IIS (Internet Information Services), 5
operating system (OS) compatibility, 7
sessions, 294
shared, security concerns, 319
web sites, 373
weblog (see blog)
WEEKDAY function, 170
WHERE clause
delete query (blog example), 355
logical operators in, 144
SELECT statement, 138
restricting your query, 139
UPDATE command, 142
UPDATE statement, 276
using an index, 160
while loops, 78
wildcards
MySQL search functions, 143
search string, 215
Win32 MSI installer binary (Apache 2.x), 16
Windows
accessing MySQL with command line, 123
MySQL datafiles directory, 156
PEAR DB installation on Windows XP Home, 193
PHP PEAR installation, 191
Windows Binaries, PHP 5.x installer, 21
word boundaries (regular expression), 331
World Wide Web, 1
X[ Top ]
XAMPP
Installation Wizard, 34
installing, 33-35
Xdebug, 116
XForms, 255
XFrames (XHTML 2.0), 255
XHTML, 251-262
browsers and, 253
generating with PHP, 261
reasons for using, 253
versions, 254-261
2.0, 255
common errors in XHTML code, 258
Document Type Definition (DTD), 256
validation tools, 257-258
XML namespaces and, 254
XML Events, 255
xmlns attribute, 254
XHTML
in Ajax, 373
XOR (logical NOR) operator, 70
XOR (logical XOR) operator, 68
XSS (cross-site scripting), 321
Z[ Top ]
Zend Framework, 372
Zend Studio, debugger tool, 116
Return to Learning PHP & MySQL