100% found this document useful (2 votes)
31 views89 pages

Php Mysql The Missing Manual Brett Mclaughlin instant download

The document provides information about the book 'PHP and MySQL: The Missing Manual' by Brett McLaughlin, including links to download the book and other related titles. It outlines the contents of the book, which covers PHP and MySQL basics, dynamic web pages, web applications, and security. The book is published by O'Reilly Media and is intended for educational and promotional use.

Uploaded by

haesegladiv8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
31 views89 pages

Php Mysql The Missing Manual Brett Mclaughlin instant download

The document provides information about the book 'PHP and MySQL: The Missing Manual' by Brett McLaughlin, including links to download the book and other related titles. It outlines the contents of the book, which covers PHP and MySQL basics, dynamic web pages, web applications, and security. The book is published by O'Reilly Media and is intended for educational and promotional use.

Uploaded by

haesegladiv8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

Php Mysql The Missing Manual Brett Mclaughlin

download

https://ebookbell.com/product/php-mysql-the-missing-manual-brett-
mclaughlin-2362166

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Php Mysql The Missing Manual Second Edition 2nd Edition Brett
Mclaughlin

https://ebookbell.com/product/php-mysql-the-missing-manual-second-
edition-2nd-edition-brett-mclaughlin-46096140

Php And Mysql The Missing Manual Brett Mclaughlin

https://ebookbell.com/product/php-and-mysql-the-missing-manual-brett-
mclaughlin-43876038

Php And Mysql The Missing Manual Brett Mclaughlin

https://ebookbell.com/product/php-and-mysql-the-missing-manual-brett-
mclaughlin-43876034

Phpmysql Programming For The Absolute Beginner Andy Harris

https://ebookbell.com/product/phpmysql-programming-for-the-absolute-
beginner-andy-harris-4105628
The Php Programming With Mysql The Web Technology Series The Web
Technologies Series 2nd Edition Don Gosselin

https://ebookbell.com/product/the-php-programming-with-mysql-the-web-
technology-series-the-web-technologies-series-2nd-edition-don-
gosselin-2471394

Php 6mysql Programming For The Absolute Beginner 1st Edition Andrew B
Harris

https://ebookbell.com/product/php-6mysql-programming-for-the-absolute-
beginner-1st-edition-andrew-b-harris-4433786

Php 6mysql Programming For The Absolute Beginner Andy Harris

https://ebookbell.com/product/php-6mysql-programming-for-the-absolute-
beginner-andy-harris-50400322

Php Mysql Novice To Ninja Get Up To Speed With Php The Easy Way 6th
Edition Tom Butler

https://ebookbell.com/product/php-mysql-novice-to-ninja-get-up-to-
speed-with-php-the-easy-way-6th-edition-tom-butler-10380008

Handson Guide To Learning All The Tools Principles And Techniques


Needed To Build A Professional Web Application Using Php Mysql Schmitt

https://ebookbell.com/product/handson-guide-to-learning-all-the-tools-
principles-and-techniques-needed-to-build-a-professional-web-
application-using-php-mysql-schmitt-46215016
PHP & MySQL
The book that should have been in the box®

Brett McLaughlin

Beijing | Cambridge | Farnham | Köln | Sebastopol | Tokyo


PHP and MySQL: The Missing Manual
by Brett McLaughlin

Copyright © 2012 Brett McLaughlin. All rights reserved.


Printed in the United States of America.

Published by O’Reilly Media, Inc.,


1005 Gravenstein Highway North, Sebastopol, CA 95472.

O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://my.safaribooksonline.com).
For more information, contact our corporate/institutional sales department: (800)
998-9938 or [email protected].

Printing History:
November 2011: First Edition.

Revision History:
2011-11-09 First release
See http://oreilly.com/catalog/errata.csp?isbn=9780596515867 for release details.

The Missing Manual is a registered trademark of O’Reilly Media, Inc. The Missing
Manual logo, and “The book that should have been in the box” are trademarks of
O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where those designations
appear in this book, and O’Reilly Media is aware of a trademark claim, the
designations are capitalized.

While every precaution has been taken in the preparation of this book, the publisher
assumes no responsibility for errors or omissions, or for damages resulting from the
use of the information contained in it.

ISBN-13: 978-0-596-51586-7
Contents

The Missing Credits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii

Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Part One: PHP and MySQL Basics


Chapter 1: PHP: What, Why, and Where?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Gathering Your Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Writing Your First Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Running Your First Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Writing Your Second Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Upload Your HTML, CSS, and PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Running Your Second Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Chapter 2: PHP Syntax: Weird and Wonderful. . . . . . . . . . . . . . . . . . . . . . . . . 25


Get Information from a Web Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Working with Text in PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The $_REQUEST Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
What Do You Do with User Information?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

Chapter 3: MySQL and SQL: Database and Language. . . . . . . . . . . . . . . . . 55


What Is a Database?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Installing MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
SQL Is a Language for Talking to Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . 76

Part Two: Dynamic Web Pages


Chapter 4: Connecting PHP to MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Writing a Simple PHP Connection Script. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Cleaning Up Your Code with Multiple Files. . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Building a Basic SQL Query Runner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

Chapter 5: Better Searching with Regular Expressions. . . . . . . . . . . . . . . 127


String Matching, Double-Time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

iii
Chapter 6: Generating Dynamic Web Pages. . . . . . . . . . . . . . . . . . . . . . . . . . 143
Revisiting a User’s Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Planning Your Database Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Saving a User’s Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Show Me the User. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Redirection and Revisitation of Creating Users . . . . . . . . . . . . . . . . . . . . . . . . 176

Part Three: From Web Pages to Web Applications


Chapter 7: When Things Go Wrong (and They Will). . . . . . . . . . . . . . . . . . . 191
Planning Your Error Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Finding a Middle Ground for Error Pages with PHP. . . . . . . . . . . . . . . . . . . . 199
Add Debugging to Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Redirecting on Error. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

Chapter 8: Handling Images and Complexity. . . . . . . . . . . . . . . . . . . . . . . . . 227


Images Are Just Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Images Are For Viewing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
And Now for Something Completely Different. . . . . . . . . . . . . . . . . . . . . . . . 258

Chapter 9: Binary Objects and Image Loading. . . . . . . . . . . . . . . . . . . . . . . 259


Storing Different Objects in Different Tables . . . . . . . . . . . . . . . . . . . . . . . . . 260
Inserting a Raw Image into a Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Your Binary Data Isn’t Safe to Insert...Yet . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Connecting Users and Images. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Show Me the Image. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Embedding an Image Is Just Viewing an Image. . . . . . . . . . . . . . . . . . . . . . .293
So Which Approach is Best? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298

Chapter 10: Listing, Iterating, and Administrating.. . . . . . . . . . . . . . . . . . . . 301


Some Things Never Change. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Listing All Your Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Deleting a User. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Talking Back To Your Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Standardizing on Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Integrating Utilities, Views, and Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . 338

iv Contents
Part Four: Security and the Real World
Chapter 11: Authentication and Authorization. . . . . . . . . . . . . . . . . . . . . . . . 353
Start with Basic Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Abstracting What’s the Same . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Passwords Don’t Belong in PHP Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Passwords Create Security, But Should Be Secure. . . . . . . . . . . . . . . . . . . . 382

Chapter 12: Cookies, Sign-ins, and Ditching Crummy Pop-ups. . . . . . . . 389


Going Beyond Basic Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Logging In with Cookies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Adding Context-Specific Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413

Chapter 13: Authorization and Sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427


Modeling Groups in Your Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Checking for Group Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Group-Specific Menus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Entering Browser Sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Memory Lane: Remember that Phishing Problem?. . . . . . . . . . . . . . . . . . . . 459
So Why Ever Use Cookies?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465

Contents v
vi Contents
The Missing Credits
About the Author
Brett McLaughlin is a senior level technologist and strategist, active especially in
web programming and data-driven customer-facing systems. Rarely focused on
only one component of a system, he architects, designs, manages, and implements
large-scale applications from start to finish with mission-critical implementations
and deadlines.
Of course, that’s all fancy-talk for saying that Brett’s a geek, spending most of his
day in front of a computer with his hands flying across a keyboard. Currently, he
spends most of his current time working on NASA projects, which sounds much
cooler than it actually is. But hey, maybe that satellite overhead really is controlled
by PHP and MySQL...

About the Creative Team


Nan Barber (editor) has been working on the Missing Manual series since its incep-
tion. She lives in Boston with her husband and various electronic devices. Email:
[email protected].
Jasmine Perez (production editor) spends her free time cooking vegetarian meals,
listening to her favorite freeform radio station, WFMU, and going on adventures
whenever possible. Email: [email protected]
Nan Reinhardt (proofreader) is a freelancer copy editor and proofreader, who is
also a writer of romantic fiction. She has two novels with her agent at Curtis Brown
Literary Agency. In between editing gigs, she is busy working on her third book.
She blogs thrice weekly at www.nanreinhardt.com. Email: [email protected].
Ron Strauss (indexer) lives with his wife in northern California at 2,300 feet. When
not indexing Missing Manual books, he moonlights as a musician (viola and Native
American flute).
Shelley Powers (technical reviewer) is a former HTML5 working group member and
author of several O’Reilly books. She is also an animal welfare advocate, working to
close down puppy mills in Missouri. Website: www.burningbird.net.
Steve Suehring (technical reviewer) is a technical architect with an extensive
background finding simple solutions to complex problems. Steve plays several
musical instruments (not at the same time) and can be reached through his
website www.braingia.org.

The Missing Credits vii


Acknowledgments
Acknowledgements are always nearly impossible to do well. Before you can think
anyone of substance, the music swells and they’re shuffling you off stage. Seriously,
before the writing, there’s my wife Leigh and my kids, Dean, Robbie, and Addie.
Any energy or joy or relaxation that happens during the long writing process filters
through those four, and there’s never enough royalties to cover the time lost with
them. I suppose it’s a reflection of their love and support for me that they’re OK
with me writing anyway.
And then, there’s certainly the writing. Brian Sawyer was the first guy to call me when
I became available to write, and he called when I was really in need of just what he
gave me: excitement about me writing and encouragement that I could write into
the Missing Manual series. I won’t forget that call anytime soon. And then Nan Barber
IM-ed and emailed me through this whole thing. She showed a really unhealthy level
of trust that wasn’t earned, and I’m quite thankful, especially in the dark days of early
August when I had hundreds of pages left to write in a few short weeks.
Shelley Powers and Steve Suehring were technical reviewers, and they were both
picky and gentle. That’s about all you can ask. Shelley helped me remember to keep
the learner front and center, and if you like the longer code listings when things get
hairy, she’s the one to thank. And Steve...Steve filled out my PHP holes. He caught
one particularly nasty issue that I think vastly improved the book. You don’t realize
this, but you owe him a real debt of thanks if this book helps you.
And then there’s the vast machinery at O’Reilly. It all works, and I don’t know how,
really, and I’m OK with that. I imagine somewhere Sanders is pulling important levers
and Courtney is badgering authors and Laura is angry and in heels and Laurie thinks
this all costs too much and Tim is...well, Tim is thinking about something important.
I’m glad for all of them.
—Brett McLaughlin

The Missing Manual Series


Missing Manuals are witty, superbly written guides to computer products that don’t
come with printed manuals (which is just about all of them). Each book features a
handcrafted index and cross-references to specific pages (not just chapters).
Recent and upcoming titles include:
Access 2010: The Missing Manual by Matthew MacDonald
Buying a Home: The Missing Manual by Nancy Conner
CSS: The Missing Manual, Second Edition, by David Sawyer McFarland
Creating a Website: The Missing Manual, Third Edition, by Matthew MacDonald
David Pogue’s Digital Photography: The Missing Manual by David Pogue
Dreamweaver CS5.5: The Missing Manual by David Sawyer McFarland

viii The Missing Credits


Droid 2: The Missing Manual by Preston Gralla
Droid X2: The Missing Manual by Preston Gralla
Excel 2010: The Missing Manual by Matthew MacDonald
Facebook: The Missing Manual, Third Edition by E.A. Vander Veer
FileMaker Pro 11: The Missing Manual by Susan Prosser and Stuart Gripman
Flash CS5.5: The Missing Manual by Chris Grover
Galaxy Tab: The Missing Manual by Preston Gralla
Google Apps: The Missing Manual by Nancy Conner
Google SketchUp: The Missing Manual by Chris Grover
iMovie ’11 & iDVD: The Missing Manual by David Pogue and Aaron Miller
iPad 2: The Missing Manual by J.D. Biersdorfer
iPhone: The Missing Manual, Fourth Edition by David Pogue
iPhone App Development: The Missing Manual by Craig Hockenberry
iPhoto ’11: The Missing Manual by David Pogue and Lesa Snider
iPod: The Missing Manual, Ninth Edition by J.D. Biersdorfer and David Pogue
JavaScript: The Missing Manual by David Sawyer McFarland
Living Green: The Missing Manual by Nancy Conner
Mac OS X Snow Leopard: The Missing Manual by David Pogue
Mac OS X Lion: The Missing Manual by David Pogue
Microsoft Project 2010: The Missing Manual by Bonnie Biafore
Motorola Xoom: The Missing Manual by Preston Gralla
Netbooks: The Missing Manual by J.D. Biersdorfer
Office 2010: The Missing Manual by Nancy Connor, Chris Grover, and Matthew
MacDonald
Office 2011 for Macintosh: The Missing Manual by Chris Grover
Palm Pre: The Missing Manual by Ed Baig
Personal Investing: The Missing Manual by Bonnie Biafore
Photoshop CS5: The Missing Manual by Lesa Snider
Photoshop Elements 9: The Missing Manual by Barbara Brundage
PowerPoint 2007: The Missing Manual by E.A. Vander Veer
Premiere Elements 8: The Missing Manual by Chris Grover

The Missing Credits ix


QuickBase: The Missing Manual by Nancy Conner
QuickBooks 2011: The Missing Manual by Bonnie Biafore
Quicken 2009: The Missing Manual by Bonnie Biafore
Switching to the Mac: The Missing Manual, Snow Leopard Edition by David Pogue
Wikipedia: The Missing Manual by John Broughton
Windows Vista: The Missing Manual by David Pogue
Windows 7: The Missing Manual by David Pogue
Word 2007: The Missing Manual by Chris Grover
Your Body: The Missing Manual by Matthew MacDonald
Your Brain: The Missing Manual by Matthew MacDonald
Your Money: The Missing Manual by J.D. Roth

x The Missing Credits


Introduction

Y
ou’ve built a web page in HTML. You’ve even styled it with Cascading Style
Sheets (CSS) and written a little JavaScript to validate your custom-built web
forms. But that wasn’t enough, so you learned a lot more JavaScript, threw in
some jQuery, and constructed a whole lot of web pages. You’ve even moved your
JavaScript into external files, shared your CSS across your entire site, and validated
your HTML with the latest standards.
But now you want more.
Maybe you’ve become frustrated with your website’s inability to store user information
in anything beyond cookies. Maybe you want a full-blown online store, complete with
PayPal integration and details about what’s in stock. Or maybe you’ve simply caught
the programming bug, and want to go beyond what HTML, CSS, and JavaScript can
easily give you.
If any of these are the case—and you may find that all these are the case!—then
learning PHP and MySQL is a great way to take a giant programming step forward.
Even if you’ve never heard of PHP, you’ll find it’s the best way to go from building
web pages to creating full-fledged web applications that store all sorts of informa-
tion in databases. This book shows you how to do just that.

xi
What Is PHP? What Is PHP?
PHP is a programming language. It’s like JavaScript in that you spend most of your
time dealing with values and making decisions about which path through your code
should be followed at any given time. But it’s like HTML in that you deal with out-
put—tags that your users view through the lens of their web browsers. In fact, PHP
in the context of web programming is a bit of a mutt; it does lots of things pretty
well, rather than just doing one single thing. (And if you’ve ever wondered why it’s
called PHP, see the box below.)

FREQUENTLY ASKED QueSTION

What Does PHP Stand For?


PHP is an acronym. Originally, PHP stood for Personal Home acronym PHP stands for something that actually contains the
Page, because lots of programmers used it to build their web- acronym PHP within itself. That makes it a recursive acronym,
sites, going much further than what was possible with HTML, or an acronym that references itself. You don’t have to know
CSS, and JavaScript. But in the last few years, “personal home what a recursive acronym is; that won’t be on the quiz. Just be
page” tends to sound more like something that happens on one warned that PHP’s recursive acronym won’t be the last weird
of those really cheap hosting sites, rather than a high-powered and slightly funny thing you’ll run across in the PHP language.
programming language.
So now PHP stands for PHP: Hypertext Preprocessor. If that
sounds geeky, it is. In fact, it’s a bit of a programmer joke: the

PHP Is All About the Web


If you came here for web programming, you’re in the right place. While you can write
PHP programs that run from a command line (check out Figure I-1 for an example),
that’s not really where PHP excels.

Figure I-1
Sure, you can run PHP programs from a Terminal win-
dow or a command shell on Windows. But most of the
time, you won’t. PHP is perfectly suited to the Web,
and that where you’ll spend most of your time.

PHP comes ready to work with HTML forms and web sessions and browser cookies.
It’s great at integrating with your website’s existing authentication system, or letting
you create one of your own. You’ll spend a lot of time not just handing off control to
an HTML page, but actually writing the HTML you’re already familiar with right into

xii PHP & MySQL: The Missing Manual


your PHP. Lots of times, you’ll actually write some PHP, and then write some HTML,
all in the same PHP file, as in the following example: What Is PHP?

<?php

require '../../scripts/database_connection.php';

// Get the user ID of the user to show


$user_id = $_REQUEST['user_id'];

// Build the SELECT statement


$select_query = "SELECT * FROM users WHERE user_id = " . $user_id;

// Run the query


$result = mysql_query($select_query);

// Assign values to variables


?>

<html>
<!-- All your HTML and inline PHP -->
</html>

The result? Pages that are both full of HTML and have dynamic content, like Figure I-2.

Figure I-2
This page is as much PHP
as HTML. It looks up your
visitor’s name in the
database and displays it
dynamically. The menu
creates a Show Profile
option specific to this
user. But there’s still lots
and lots of HTML. This is
PHP at its best: combining
the HTML and even
JavaScript that you know
with the PHP you’re about
to learn.

Introduction xiii
What Is JavaScript Is Loose, PHP Is…Less So
MySQL?
If you’ve written some JavaScript—and if you’re checking out this book, that’s prob-
ably the case—then you know that JavaScript lets you do just about anything you
want. You can occasionally leave out semicolons; you can use brackets, or not; you
can use the var keyword, or not. That sort of looseness is both great for getting
things working quickly, and at the same time, frustrating. It makes finding bugs tricky
at times, and working across browsers can be a nightmare.
PHP is not quite so loose as JavaScript, so it makes you learn a little more structure
and tighten up your understanding of what’s going on as your program is interpreted.
That’s a good thing, as it’ll end up making you tighten up your JavaScript skills, too.
And, perhaps best of all, PHP’s stodgy consistency makes it easier to learn. It gives
you firm rules to hang on to, rather than lots of “You can do this…or this…or this…”
So get ready. There’s lots to learn, but everything you learn gives you something
to build on. And PHP lets you know right away when there’s a problem. You won’t
need to pop open an Error Console or keep an eye out for Internet Explorer’s tiny
yellow warning triangle like you do with JavaScript.

PHP Is Interpreted
PHP code comes in the form of scripts, which are plain text files you write. The PHP
interpreter is a piece of software on your web server that reads that file and makes
sense of it, giving the Web server HTML output and directions about where to go
next, or how to interpret a user’s form entry. Your text file is interpreted, one line at
a time, every time that file is accessed.
This scheme is different from languages like Java or C++, which are compiled. In
those languages, you write in text files, but then run a command that turns those
text files into something else: class files, binary files, pieces of unreadable code that
your computer uses.
The beauty of an interpreted language like PHP—and JavaScript, for that matter—is
that you write your code and go. You don’t need a bunch of tools or steps. You write
PHP. Test it out in the browser. Write some more. It’s fast, and that usually means
it’s pretty fun.

What Is MySQL?
MySQL is a database. It stores your information, your users’ information, and any-
thing else you want to stuff into it. There’s actually a lot more nuance to MySQL—and
SQL, the language in which you’ll interact with MySQL (but better to save that for
Chapter 3—when you’ve got a little PHP and context under your belt).
For now, think of MySQL as a warehouse where you can store things to be looked
up later. Not only that, MySQL provides you a really fast little imp that runs around
finding all that stuff you stuck in the warehouse whenever it’s needed. By the time
you’re through this this book, you’ll love that imp…er…MySQL. It’ll do work that you
could never do on your own, and it’ll do that work tirelessly and quickly.

xiv PHP & MySQL: The Missing Manual


About This
About This Book Book
PHP is a web-based language, not a program that comes in a box. And there are
literally tens (hundreds?) of thousands of websites that have bits of PHP instruction
on them. That’s great, right? Well, not so much. Those websites aren’t all current.
Some are full of bugs. Some have more information in the comment trails—scattered
amongst gripes, complaints, and lambasting from other programmers—as they do
in the main page. It’s no easy matter to find what you’re looking for.
The purpose of this book, then, is to serve as the manual that should have been
included when you download PHP. It’s the missing PDF, if you will (or maybe the
missing eBook, if you’re a Kindle or Nook or iPad person). In this book’s pages, you’ll
find step-by-step instructions for getting PHP running, writing your first program…
and your second program…and eventually building a web application from scratch. In
addition, you’ll find clear evaluations of the absolutely critical parts of PHP that you’ll
use every day, whether you’re building a personal weblog or a corporate intranet.

Note This book periodically recommends other books, covering topics that are too specialized or tangential
for a manual about PHP and MySQL. Careful readers may notice that not every one of these titles is published
by Missing Manual parent company O’Reilly Media. If there’s a great book out there that doesn’t happen to be
published by O’Reilly, this book will still let you know about it.

PHP & MySQL: The Missing Manual is designed to accommodate readers at every
technical level. The primary discussions are written for advanced-beginner or inter-
mediate Web authors and programmers. Hopefully, you’re comfortable with HTML
and CSS, and maybe even know a bit of JavaScript. But if you’re new to all this Web
stuff, take heart: special boxes called “Up to Speed” provide the introductory infor-
mation you need to understand the topic at hand. If you’re an advanced user, on the
other hand, keep your eye out for similar boxes called “Power Users’ Clinic.” They
offer more technical tips, tricks, and shortcuts for the experienced computer fan.

Macintosh and Windows


PHP and MySQL work almost precisely the same in their Macintosh and Windows
versions. And even more importantly, you’ll do most of your work by uploading
your scripts and running your database code against a web server. That means that
your hosting provider gets to deal with operating system issues. You get to focus
on your code and information.
In the first few chapters, you’ll get your system set up to code and deal with PHP
scripts. But you’ll soon forget about whether you’re on Mac or Windows. You’ll just
be writing code, the same way you write HTML and CSS.

FTP: It’s Critical


One piece of software you won’t forget you’re using is a good FTP program. Most
PHP programmers don’t sit on a remote server typing into a command-line editor
like vi or emacs.

Introduction xv
About This
Author’s Note
Book Typing in a command-line editor is actually exactly how I work. But then, I’m a
dinosaur, a throwback to days when you had to watch commercials to see primetime TV, and you’d miss emails
because your pocket didn’t buzz every time your boss whisked you a command through the ether.
Today, for most of you, a good text editor and a good graphical FTP client are much better choices. Seriously, my
addiction owns me, and I so badly want to :wq! it.

Chapter 1 will point you at several great editors, and the fancier ones will have FTP
built right in. But a program like Cyberduck (www.cyberduck.ch) is great, too. You
can write a script, throw it online, and test it all with a few mouse clicks. So go ahead
and get that FTP program downloaded, configured for your web server, and fired
up. You’re gonna need it.

About the Outline


PHP & MySQL: The Missing Manual is divided into four parts, each containing several
chapters:
• Part 1: PHP and MySQL Basics. In the first three chapters, you’ll install PHP,
get it running on your computer, write your first few PHP programs, and learn
to do a few basic things like collect user information via a web form and work
with text. You’ll also install MySQL and get thoroughly acquainted with the
structure of a database.
• Part 2: Dynamic Web Pages. These are the chapters where you start to build
the basics of a solid web application. You’ll add a table in which you can store
users and their information, and get a grasp of how easily you can manipulate
text. From URLs and emails to Twitter handles, you’ll use regular expressions
and string handling to bend letters, numbers, and slashes to your will.
• Part 3: From Web Pages to Web Applications. With a solid foundation, you’re
ready to connect your web pages into a more cohesive unit. You’ll add custom
error handling so that your users won’t get confused when things go wrong,
and your own debugging to help you find problems. You’ll also store references
to users’ images of themselves, store the images themselves in a database, and
learn which approach is best in which situations.
• Part 4: Security and the Real World. In even the simplest of applications, logging
in and logging out is critical. You’ll build an authentication system, and then deal
with passwords (which are important, but a bit of a pain). You’ll then work with
cookies and sessions, and use both to create a group-based authorization system
for your web application.
At the Missing Manual website (www.missingmanuals.com/cds/phpmysqlmm), you’ll
find every single code example, from every chapter, in the state it was shown for
that chapter.

xvi PHP & MySQL: The Missing Manual


About the
Online
About the Online Resources Resources
As the owner of a Missing Manual, you’ve got more than just a book to read. Online,
you’ll find example files so you can get some hands-on experience, as well as tips,
articles, and maybe even a video or two. You can also communicate with the Missing
Manual team and tell us what you love (or hate) about the book. Head over to www.
missingmanuals.com, or go directly to one of the following sections.

Missing CD
This book doesn’t have a CD pasted inside the back cover, but you’re not missing
out on anything. Go to www.missingmanuals.com/cds/phpmysqlmm to download
code samples, code samples, and also, some code samples. Yup, there are a lot of
them. Every chapter has a section of code for that chapter. And you don’t just get
completed versions of the book’s scripts. You’ll get a version that matches up with
each chapter, so you’ll never get too confused about exactly how your version of a
script or web page should look.
And so you don’t wear down your fingers typing long web addresses, the Missing
CD page also offers a list of clickable links to the websites mentioned in this book.

Registration
If you register this book at oreilly.com, you’ll be eligible for special offers—like discounts
on future editions of PHP & MySQL: The Missing Manual. Registering takes only a few
clicks. To get started, type www.oreilly.com/register into your browser to hop directly
to the Registration page.

Feedback
Got questions? Need more information? Fancy yourself a book reviewer? On our
Feedback page, you can get expert answers to questions that come to you while
reading, share your thoughts on this Missing Manual, and find groups for folks who
share your interest in PHP, MySQL, and web applications in general. To have your
say, go to www.missingmanuals.com/feedback.

Errata
In an effort to keep this book as up-to-date and accurate as possible, each time we
print more copies, we’ll make any confirmed corrections you’ve suggested. We also
note such changes on the book’s website, so you can mark important corrections
into your own copy of the book, if you like. Go to http://tinyurl.com/phpmysql-mm
to report an error and view existing corrections.

Introduction xvii
Safari® Books
Online​ Safari® Books Online
Safari® Books Online is an on-demand digital library that lets you
easily search over 7,500 technology and creative reference books
and videos to find the answers you need quickly.
With a subscription, you can read any page and watch any video from our library
online. Read books on your cell phone and mobile devices. Access new titles before
they are available for print, and get exclusive access to manuscripts in development
and post feedback for the authors. Copy and paste code samples, organize your
favorites, download chapters, bookmark key sections, create notes, print out pages,
and benefit from tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have
full digital access to this book and others on similar topics from O’Reilly and other
publishers, sign up for free at http://my.safaribooksonline.com.

xviii PHP & MySQL: The Missing Manual


Part

PHP and MySQL Basics 1

Chapter 1:
PHP: What, Why, and Where?
Chapter 2:
PHP Syntax: Weird and Wonderful
Chapter 3:
MySQL and SQL: Database and Language
chapter

1
PHP: What, Why,
and Where?

P
HP is ultimately text, taken by your web server and turned into a set of commands
and information for your web browser. And because you’re just working in text,
there’s not a lot you have to do to get going as a PHP programmer. You need to
get familiar with PHP itself—and the best way to do that is to install PHP on your own
computer, even though most of your programs will run on a web server.
Then, you need to run an actual script. Don’t worry; it’s amazingly easy to write your
first program in PHP, and you’ll end up writing more than just one program before
you hit Chapter 2.
And through it all? You’ll begin taking control. PHP gives you the ability to be an
active participant in your web pages. It lets you listen carefully to your users and
say something back. So get going; no reason to leave you users with passive HTML
pages any longer.

Gathering Your Tools


You’ll need to take just a few steps before you can start with PHP. You can’t build a
website without a web browser, and you can’t write PHP without a few tools. But it
won’t take long before you’ve got your computer set up with your own customized
PHP programming environment.
Although PHP isn’t pre-loaded on every computer like web browsers are, you can
easily download PHP from the Internet, get it working on your computer, and get up
and running fast…all without spending a dime. On top of that, most of the easiest

3
Gathering and best tools for writing PHP code are also free. All you need is your own copy of
Your Tools the PHP language on your computer, plus a plain old text editor. This section shows
you where to find them.

PHP on the PC
PCs come with a lot of software pre-installed. Unfortunately, one program that most
PCs don’t come with is PHP. That’s okay though: you can get PHP up and running
in just a few minutes, as long as you have an Internet connection.

Note If you have a Mac, you don’t have to go through this installation process. Flip to page 9.

Open up your favorite Web browser and head to www.php.net. This site is PHP’s
online home, and it’s where you’ll download your own version of the PHP language,
along with all the tools you need to write and run PHP programs. Look along the
right side of the PHP home page for the Stable Releases heading; you can see it on
the right of Figure 1-1.

Figure 1-1
If you ever want to
download a new version
of PHP—or update the
version you’ve already
got—then www.php.net is
the place to visit.

Click the link for the version with the highest number. (For more information on what
all these versions mean, see the box on the next page.)

4 PHP & MySQL: The Missing Manual


Once you’ve chosen a PHP version link, you’ll see a screen like Figure 1-2, with links Gathering
for the current version of PHP as well as at least one older version (which will have Your Tools
a lower version number than the most current version).
Before you download PHP, though, take a look further down the page. There’s
a heading titled Windows Binaries, and that’s your ticket to getting PHP up and
running fast on your Windows machine. Clicking this link takes you to another site,
http://windows.php.net/download, which should look something like Figure 1-3.

Figure 1-2
The PHP site always has
at least the latest stable
version, and the previous
stable version available
for download. Unless
you’ve got a really good
reason to do otherwise,
always go with the latest
stable version.

UP TO SPEED

Release the Version Within


If you’ve never worked with software that comes in versions software people (yes, they really exist) use version numbers
or releases, there’s nothing to worry about. Both words mean (or release numbers) to do that. Generally, software begins
pretty much the same thing when it comes to software: A ver- at 1.0 and that number gets higher as the software adds new
sion or release of software is just a way of saying that all the features. So version 2.2 of PHP is going to be newer than ver-
parts of that software are packaged together so that they work sion 1.1, and probably will have some cool new features, too.
correctly for you, and with the other parts of that software. Sometimes, as on the PHP website, you’ll see several different
Since software changes frequently, though, the folks that make packages or downloads of a piece of software, each with a
software need a way to say, “Hey, our software has some new different version number. You can usually just download the
cool bells and whistles! There’s a new package available!” The latest version of the software you want and you’ll be all set.

Chapter 1: PHP: What, Why, and Where? 5


Gathering This page has options for the latest version and well as several older versions. For
Your Tools the newest version, there will be two big gray blocks: the first for the Non Thread
Safe version, and the second for the Thread Safe version. You want to download the
Non Thread Safe version, since it runs much faster. (For more detail on the difference
between these two versions, see the box on page 7.)

Figure 1-3
PHP has a page dedicated
to Windows downloads.
There are still a lot of
options, but don’t get too
distracted by so many
choices. You’re looking for
a single word: Installer.

Just look for the Installer option and click the link. The installer is usually a big
download, but includes a nice Windows installer that will make getting PHP running
a breeze. Click this link and then grab a cup of coffee while you’re waiting for your
download to complete.

Note If you’re thinking you could have just gone directly to http://windows.php.net/download/ , then you’re
right: You could have. But six months from now, you may forget that longer URL, but remember www.php.net. On
top of that, a good old-fashioned Google search for PHP takes you to www.php.net, so it’s a good idea to learn
how to get to the Windows installer from the main PHP home page.

Once your download’s done, find the downloaded file and double-click it. When
Windows asks for permission to run the installer, click Allow, and then click Next on
the pop-up screen to start the installation.
You’ll have to accept a license agreement and then select an installation directory.
Go with the suggested C:\Program Files\PHP\ , so you can always find PHP with all

6 PHP & MySQL: The Missing Manual


your other programs. Next, the installer asks about configuring a web server (see Gathering
Figure 1-4). For now, you’ll be using PHP on your machine to test programs, and then Your Tools
uploading those programs to a web server, so select “Do not setup a web server.” If
you want to add a web server later, you can always come back and change this option.

Figure 1-4
If you want to install a local web server to test
your entire web applications on your machine,
select the IIS FastCGI or Other CGI option. But for
getting started, “Do not setup a web server” is
the simplest option.

UNDER THE HOOD

PHP on Windows: Fast or Safe?


PHP was first released in a Windows-friendly version back in Still, not everyone liked installing PHP and then having to
2000. In those early releases, PHP was released only in one ver- install a tweaked web server, or make manual changes to PHP,
sion: Thread Safe. While Mac OS X and Unix/Linux systems use to get it running at tip-top speed. As a result, there’s now a
something called processes to run multiple things at one time, non-thread safe option. This option doesn’t concern itself
Windows systems use threads . Those Windows threads can with other threads, and the result is a significant performance
interact with each other, and so to prevent them from screwing increase, ranging anywhere from 10 to 40 percent, depending
each other up, PHP came in a version that was thread safe. on your applications.
Unfortunately, keeping those threads out of each other’s way Chances are, if you don’t have a strong opinion or idea about
takes a lot of time. The thread-safe version of PHP on Windows which version of the PHP binaries you need, you’ll do fine with
is slow, and PHP programmers flocked away from Windows the non-thread safe binaries, and you’ll get a nice snappy
whenever possible. A few clever PHP programmers figured out performance. If you have real concerns about the non-thread
ways to recycle threads, and now a lot of web servers that run safe version—perhaps you never want two users competing
on Windows now come pre-installed with a PHP version that for the same piece of data, regardless of how fast or slow your
can recycle threads right from the start. application runs—then you can certainly choose the thread-
safe binaries and tweak your own installation as you see fit.

Chapter 1: PHP: What, Why, and Where? 7


Gathering The next screen asks you which items to install. The default options, shown in Figure
Your Tools 1-5, are fine for now. Just click Next to move on.

Figure 1-5
The Windows installer comes with the basic PHP
installation, but you can also add several extras,
which you can access by clicking the white box
next to Extras and selecting individual features.

Finally, click Install and then let your progress indicator march to full. That’s it! You’ve
got PHP running on your machine.
To check out PHP, go to your Start menu and type cmd in the Search box. A command
window opens, into which you can type commands like those that run PHP. Go ahead
and type php, as you see in Figure 1-6.
Even though it doesn’t look like much, that blank line and empty command prompt
mean PHP is installed correctly. Now you’re ready to get into your first program.

Figure 1-6
You won’t spend a lot of
time running PHP from
the command prompt,
but it’s a nice quick way
to test things out. The
Windows installer makes
sure you can run PHP
from anywhere on the
command line, from any
directory.

8 PHP & MySQL: The Missing Manual


PHP on the Mac Gathering
Your Tools
There’s something downright sexy about Macs. All that metal and chrome...and,
for the programmer, PHP! That’s right, if you’ve got a Mac, you’ve already got PHP
pre-installed. To prove it, open the Terminal application on your Mac.
If you’ve never used Terminal, don’t worry; you’ll get used to it quickly and find it’s
one of your best friends for working with PHP. Open your Applications folder (you can
use Shift-c-A as a shortcut), and then look for the Utilities folder, shown in Figure 1-7.

Warning Shift-c-A works only if your desktop or another file folder is active. If you’re currently viewing
this book in an e-reader or online, for example, click your desktop and then press Shift-c-A.

Figure 1-7
The Utilities folder
hides all sorts of useful
programs that come with
Mac OS X. Look around,
as there are all sorts of
goodies you may want to
use regularly.

Power Users’ Clinic

Opening Programs Without the Mouse


There’s nothing wrong with opening a folder in the Finder and to take some time to learn these shortcuts as you run across
using your mouse to locate the Applications folder, and then the them in software menus or these chapters.
Utilities folder. But you’ll find that programmers are impatient This book will give you both the folder path and keyboard
folks, and you can move a lot quicker if you don’t have to take shortcut when one exists. You’ll find folder paths expressed
your hands off your keyboard so often. Keyboard shortcuts like with arrow notation, as in Applications➝Utilities.
Shift-c-A are perfect ways to do just that, so you may want

Chapter 1: PHP: What, Why, and Where? 9


Gathering Once you’ve found the Applications folder, open it and find the Terminal applica-
Your Tools tion. It looks like a computer monitor with black screen and a little white arrow, as
you see in Figure 1-8.

Figure 1-8
The Terminal program lets
you use a command line
on Macs. A lot of your PHP
coding will be done using
Terminal, so you’ll get
used to this application
pretty quickly.

Tip You’ll often use the Terminal application for testing out your PHP programs before you upload them to
your server. To make it easier to launch Terminal, you may want to drag the icon into your dock so you can quickly
launch Terminal in the future.

Double-click the Terminal icon, and you’ll see a white rectangular screen with a little
black cursor blinking, as in Figure 1-9. That little cursor is going to be one of your
best friends on your journey to PHP nirvana.

Figure 1-9
When you first open Terminal, you
won’t be too impressed. You’ll get
a line that probably matches your
computer’s name, and then a weird
dollar sign. Don’t worry—this will all
soon be old hat.

To make sure PHP is installed on your system, just type php, all in lowercase letters,
and hit Enter. Unfortunately, the way to know things are working is if you don’t see

10 PHP & MySQL: The Missing Manual


anything but that blank cursor, a little further down in Terminal. It won’t even blink Gathering
at you anymore; it’s just a boring gray dark square. Your Tools

Hit Control-C to stop that single eye from staying, and you’ll get a blinking cursor
again. This time, type which php. The which command tells you where on your
computer the program you give it is located—php in this case. You’ll probably get
something back that looks like Figure 1-10; here, php is in the /usr/bin directory.
You’ll probably get a similar result.

Figure 1-10
Lots of the programs you use in
Terminal are scattered around
your Mac’s hard drive. The which
command lets you know exactly
where a command really resides on
your machine.

Once you’ve seen exactly where php is, you’re ready to go!

Power Users’ Clinic

Take Control of Your PHP Installation


Like most of the programs on your computer, the PHP software Look at the very first line that PHP spits out; it tells you you’re
package (which includes the php program you’ve been run- running version 5.3.4. (See the box on page 5 for more detail
ning) is updated fairly often. Most of the time, if you’re keeping on how version numbers work.)
your computer updated with Apple’s Software Update, you If you want to get the very latest version of PHP, you can visit
don’t have to worry about updating PHP separately. But if you www.php.net and download the PHP source code. That’s a
want to see what version of PHP you’re actually running, you little trickier than just using the version preinstalled on your
can type php –version into your Terminal window. You’ll get Mac, though, so unless you’re really into commands like unzip
back something like this: and tar, you can stick with what’s already on your machine.
Bretts-MacBook-Pro:~ bdm0509$ php -version By the way, if you’re not using your Mac’s Software Update
PHP 5.3.4 (cli) (built: Dec 15 2010 frequently, you may want to do so now. It’ll keep your software
12:15:07) current, without all the hassle of downloading programs on
Copyright (c) 1997-2010 The PHP Group your own. Just choose •➝Software Update to find and install
new software that’s available for your Mac. And if your software
Zend Engine v2.3.0, Copyright (c) 1998-
is up to date, the dialog box lets you know.
2010 Zend Technologies

Get Out Your Text Editor


All the programs you’re going to write in PHP are plain old text files. In fact, writing
PHP isn’t much different from writing HTML or CSS or JavaScript. You’ll type different
things, but these are all just text files saved with a special extension. You use .html
for HTML, .css for CSS, .js for JavaScript, and now .php for PHP files.

Chapter 1: PHP: What, Why, and Where? 11


Gathering Since PHP is just text, you’ll want a good text editor to work in. As simple as those
Your Tools programs are, they’re perfect for coding in PHP. If you’re on Windows, then you can
use Notepad. If you’re on a Mac, then TextEdit is a great choice. The good news is
that each of these programs comes pre-installed on your computer, so you don’t
have to download anything, and you don’t have to buy anything. The bad news is
that none of these programs knows you’re writing PHP, so you don’t get much help
spotting typos or organizing your files.
On the other hand, you’ll find quite a few editors out there that are built to specifi-
cally handle PHP. For instance, on Windows, you can download NuSphere PhpED
(www.nusphere.com/products/phped.htm), shown in Figure 1-11. You’ll pay a bit
for a program like NuSphere—usually between $50 and $100—but you’ll get fancy
color-coding, help with special language features, and in a lot of cases, some pretty
nifty file organization and even the ability to upload your PHP directly to your web
server, as discussed on page 20.

Figure 1-11
NuSphere PhpED gives
you a ton of features,
and supports JavaScript,
CSS, and HTML, as well as
PHP. It’s also got great
documentation for most
of the PHP functions and
libraries.

If you’re on a Mac, then the two leading candidates for editors that do text plus lots
of other cool things are BBEdit (www.barebones.com/products/bbedit/index.html)
and TextMate (www.macromates.com). Both are Mac-only programs, and both offer
similar features to what PhpED offers on Windows: color-coding, file management,
help documentation, and support for HTML, CSS, JavaScript, and a lot more. You can
see BBEdit in action in Figure 1-12; you’ll need to drop $100 to get going with BBEdit.
You can see what TextMate looks like in Figure 1-13. It looks a little simpler than
BBEdit, and if you’ve never used a programming editor, it might be a little easier to
begin with. It’s going to cost you about $60, slightly less than BBEdit.

12 PHP & MySQL: The Missing Manual


Gathering
Your Tools

Figure 1-12
BBEdit is supposed to be
bare bones, but you’ll
find it’s got more than
adequate PHP support.
It’s tuned primarily for
HTML, so there are a few
oddities, but it’s a great
choice for PHP work on
the Mac.

Figure 1-13
TextMate is an editor that
seeks to provide color-
coded editing and not
much else. It does offer
file management and FTP
support, but it’s best at
letting you type code and
staying out of the way.

UNDER THE HOOD

Text Editors: Mashing Up Programs


Although programs like PhpED, BBEdit, and TextMate are billed opposed to lots of programs that only do one thing, but do that
as text editors, they’re really lots of programs rolled into one. one thing really well.
Imagine having a text editor, a file management tool like Lots of the time, you’re making a choice between convenience
Windows Explorer or the Mac’s Finder, a telnet or terminal and features. If you only use FTP to upload files to a server on
program, an FTP client, and then some glue to hold them all occasion, you almost never work with your computer’s com-
together. That’s what these programs give you: a bunch of mand line, and you get a kick out of color-coded text, then
things all rolled into one single bit of software. the bundled text editors with lots of extra features might be
What’s great about these “text editors plus” is that they offer a really good fit.
you all sorts of features, and you don’t need five or six icons in Whether you use a more fully featured text editor or not,
your Mac’s dock or shortcuts on your Windows desktop. You’ve though, at some point you may need to ditch the editor
got access to almost everything you’ll need for building web and use the actual FTP or telnet programs. As long as you’re
pages or programming in PHP at your fingertips. comfortable diving into those programs without the use of an
What’s not so great, though, is that generalized tools aren’t often editor from time to time, then go forth and code in TextMate
as full-featured as specific tools. In other words, a program that or PhpED without worry.
tries to do everything usually does lots of things decently, as

Chapter 1: PHP: What, Why, and Where? 13


Writing
Your First Once you’re comfortable writing PHP code, spend some time playing with different
Program enhanced editors to see which one is best for you. Or you may find that you’re a
Notepad or TextEdit programmer at heart after all. There’s no one right option for
PHP; all these choices work just fine.
Just starting out, though, try and use a simple text editor—Notepad on Windows
or TextEdit on the Mac. You’ll learn a lot more about PHP this way, even if you
don’t get all the bells and whistles of one of the editors that offer lots of extra
features. Besides, once you really understand PHP and have learned to use its
features manually, you’ll appreciate and even be able to use the features of the
other editors a lot more effectively.

Note Once you’ve become familiar with PHP, you can also check out Eclipse PHP ( www.eclipse.org/
projects/project.php?id=tools.pdt). The Eclipse IDE has long been a favorite for Java developers, and there are
now enough plug-ins for PHP that it’s a legitimate option for PHP programmers, too. However, there’s a lot going
on in Eclipse—tons of tools and gadgets—so you might want to wait a bit before you dive head first into Eclipse
PHP. Come back to it later, though; it’s well worth checking out.

Writing Your First Program


You’ve got PHP; you’ve got a text editor. Now all you need is a PHP program, which
you’ll create in the next few minutes. Open up your text editor, and type the follow-
ing code, exactly as shown:
<?php

echo "Hello there. So I hear you're learning to be a PHP programmer!\n";


echo "Why don't you type in your name for me:\n";
$name = trim(fgets(STDIN));

echo "\nThanks, " . $name . ", it's really nice to meet you.\n\n";

?>

A lot of this code may look weird to you, and that’s OK. You’ll understand every bit
of it soon. Right now, just get used to looking at PHP, which is quite a bit different
from HTML or JavaScript.

Warning Some of the editors you might use, like TextEdit, automatically create rich text documents.
Rich text lets you use formatting, like bolding and underlining. You don’t want that in your PHP code, so look for
the option to use plain text, which doesn’t allow formatting.
If you’re using TextEdit, choose Format➝Make Plain Text. You won’t have that option if you’re already typing in
plain text. If you’re using Notepad, rich text isn’t an option, so you’ve got nothing to worry about.

14 PHP & MySQL: The Missing Manual


Writing
Your First
Once you’re done, your editor should look something like Figure 1-14. Program

Figure 1-14
PHP is just text, but it’s got several weird characters.
You’ll want to start getting used to typing the dollar
sign ($), angle brackets (< and >, just as in HTML), and
the backslash (\). You’ll be using those characters a
whole lot.

This program does just a few simple things:


1. Identifies itself as PHP using <?php
2. Prints out a welcome message using the echo command
3. Asks the visitor for his name, again using echo
4. Gets the visitor’s name and stores it in something called $name
5. Says hello by printing out a message followed by what’s in $name
6. Finishes up with the ?> characters
It’s okay if a lot of this doesn’t make sense, but you probably already could have
figured out a lot of this, except maybe the weird line beginning with $name =. There
are also some strange characters, like \ns and STDIN, that you’ll learn about soon.
Just see if you can follow the basic path of things: the opening <?php, the printing,
the request for the user’s name, another bit of printing, and the closing ?>.
Now save this program. Name it sayHello.php, and make sure you add that .php
extension. Otherwise you’ll have problems down the line. Save the file some place
handy, like on your desktop, in your home directory, or in a folder you’re using to
keep all your PHP programs in as you’re learning.

Note Most programs on Windows and the Mac will supply you a default extension, like .txt. Make sure you
replace that with .php. Windows especially tends to hide extensions, so make sure your full filename is sayHello.php,
not something like sayHello.php.txt.

That’s it; you’ve written your first PHP program!

Chapter 1: PHP: What, Why, and Where? 15


Running
Your First
Program

POWER USERS’ CLINIC

Default to Plain Text


Most of the popular text editors let you change from rich text TextEdit on the Mac, open the Preferences menu. At the very
to plain text on a per-file basis, but they start out in rich text top, under Format, you can set the default mode as Plain Text
mode by default. That can become a pain, so you may want to (as shown in Figure 1-15). On Windows, using Notepad lets you
change your editor to always start out in plain text mode.For avoid this entire issue, so you’ve got nothing to worry about.

Figure 1-15
You can get to the TextEdit preferences under the Prefer-
ences menu, or with the shortcut combination c-,. In the
Preferences box, you’ve got lots of options, but the text
format and font used for plain text are the most important
for now.

Running Your First Program


What good is it to get all this code typed in if you can’t see if it works? This particular
program isn’t ready to run on the Web yet, so you’ll need to use the command line.
You used the command line earlier to make sure PHP was installed correctly (page
8). Fire up your command line program again. If you’re on a Mac, you’ve already
opened up Terminal, and may even have a shortcut in your dock. Open Terminal again.
Now change into the directory in which you saved your program, sayHello.php.
You can do a directory listing with dir (on Windows) or ls (on the Mac) to make sure
you’re in the right directory. Once you’re in the right directory, type the following
into your command line:
php sayHello.php

16 PHP & MySQL: The Missing Manual


Writing
This tells the php program to run, and gives it your program, sayHello.php, as what Your Second
to run. Pretty quickly, you should see the welcome message you typed, and then Program
the program asks you for your name. Go ahead and type your name, and then hit
Enter. The program should then greet you, just as shown in Figure 1-16.

Figure 1-16
Eventually, you’ll run most of your
PHP scripts through a web browser.
For now, though, the command line
lets you take control of the php com-
mand and give it a particular script
to run, and then see the output on
the command line.

That’s it! Your first program works, and you’re ready to go deeper into PHP.

Writing Your Second Program


Why wait around before going a little further into PHP? You probably got interested
in PHP because you wanted to make your web pages do a little more than is possible
with JavaScript. If that’s the case, PHP is a great language, and you need to learn
how to get code like you’ve already written onto the Web. And because most PHP
programs are accessed by web pages, you’ll often start your PHP programming with
an HTML page that will send information to your PHP scripts.

Start with an HTML Page


To get started, open up a new document in your text editor or favorite HTML editor,
and create this HTML page:
<html>
<head>
<link href="../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 1-1</div>

<div id="content">
<h1>Welcome!</h1>
<p>Hello there. So I hear you're learning to be a PHP programmer!</p>
<p>Why don't you type in your name for me:</p>
<form action="scripts/sayHelloWeb.php" method="POST">
<p>

Chapter 1: PHP: What, Why, and Where? 17


Writing
Your Second <i>Enter your name:</i> <input type="text" name="name" size="20" />
Program </p>
<p><input type="submit" value="Say Hello" /></p>
</form>
</div>

<div id="footer"></div>
</body>
</html>

Note You can download this HTML, along with the rest of the book’s sample files, from www.missingmanuals.com/
cds/phpmysqlmm. You can also get the CSS and images used by the samples, which let you give your programs a little extra
visual pizzazz. Still, especially as you’re just getting started, you’ll learn a lot more if you’ll type in the PHP code for these
programs yourself.

Almost nothing about this page should be new to you. All it does is reference an
external CSS style sheet, provide a text greeting like sayHello.php did, and then
define a form into which users can type their names.
The only thing that should have caught your attention is this line, in the form
definition:
<form action="scripts/sayHelloWeb.php" method="POST">

This code means that your form is going to submit its information to a program
called sayHelloWeb.php, a new PHP program you’re about to write. Once the form
is submitted, sayHelloWeb.php takes over and prints out the welcome message.

Write a PHP Script


Now that you’ve got an HTML page sending information to sayHelloWeb.php, you
need to actually write that code. When you write PHP to run on the Web, it’s not
much different from the program you’ve already written (page 14). You have to get
information a little differently, because there’s no command line that a user can type
into. But other than that, things stay pretty much the same.
Open up a new text editor and type the PHP code shown here; it should look sort
of like an HTML-ized version of the sayHello.php program:
<html>
<head>
<link href="../../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 1-1</div>

<div id="content">

18 PHP & MySQL: The Missing Manual


Writing
<h1>Hello, <?php echo $_REQUEST['name']; ?></h1> Your Second
<p>Great to meet you. Welcome to the beginning of your PHP programming Program
odyssey.</p>
</form>
</div>

<div id="footer"></div>
</body>
</html>

Save this program as sayHelloWeb.php, and be sure you’ve got your file in plain
text with the right extension.
The first thing you probably noticed here is that this file looks a whole lot like HTML.
In fact, compared to sayHello.php, the first PHP program you wrote, this version
might look like a style of programming that’s a lot easier to learn. That’s because
once you’re using PHP to work and interact with web pages, a lot of what your PHP
programs will do is insert data into existing web pages, which means you’ll be work-
ing with HTML a lot. Of course, that’s great news, because you already know HTML,
so you’ll be adding to what you know, rather than learning something completely
new from scratch.
Once you realize that a lot of this program is just HTML, you can probably already
guess what a lot of this program does. Here’s a section-by-section breakdown:
• The page starts out with a normal html element and head section.
• The body section begins, and sets up the page heading and example number,
just like the regular HTML page, sayHello.html.
• The page defines a heading with h1, and prints “Hello,.“
• The <?php tells the browser some PHP code is coming. Then, then $_REQUEST
variable is accessed, and a property called name within that variable is printed
using echo.
• The end of the PHP code is indicated with ?>.
• The rest of the HTML is output, just as in sayHello.html.
This program, like most PHP programs you’ll write, accepts its input from a web
page, either from one built in HTML like the pages you’ve created before, or from
another PHP program. It’s the job of that web page—sayHello.html in your case—to
get the user to enter her information, and then send that information on to this
program. The information from that HTML page is stored in $_REQUEST, which is
a special variable in PHP.

Variables Vary
A variable in PHP, or any other programming language, is something that stores a
value. Variables have names, and in PHP, those names can be almost anything you

Chapter 1: PHP: What, Why, and Where? 19


Upload Your
HTML, CSS, want. You can tell that something is a variable in PHP because the name starts with
and PHP a $. So $myHeight is a variable called “myHeight,” and $_REQUEST is a variable
called “_REQUEST.”

Note Technically, the name of a PHP variable does not include the $, but most PHP programmers consider
that $ a part of the variable itself. So you’ll hear PHP programmers say things like “dollar my height” instead of
just “myHeight” to refer to $myHeight.

Variables are not just names, though. They also have a value. So the value of
$myHeight might be the number 68 (for 68 inches) or the text “68 inches.” In
PHP, though, you’re not stuck with that value forever. You can change the value
of a variable, which is where the word variables actually comes from: a variable
varies, or changes.
In sayHelloWeb.php, you’re using the special PHP variable $_REQUEST to get the
user’s name, which he entered into the form you built in sayHello.html. PHP gives you
the ability to get to anything a user entered into a form using $_REQUEST and the
name of the form entry field—in this case, “name.” So $_REQUEST['name'] returns
the information a user put into a web form, specifically into an input field called
“name.” If the user also entered in their phone number, say, into a form field called
“phoneNumber,” you could get that value in PHP with $_REQUEST['phoneNumber'].

Note It’s okay if you’re still a little fuzzyon the details of how variables and $_REQUEST work. You’ll learn
a lot more about variables and in particular special variables in PHP like $_REQUEST in the next few chapters.

Once your PHP program grabs the value from the “name” form field, it prints that
value out using echo, something you’ve already used in your first PHP program. That
value gets dropped right into the HTML sent back to the browser…something you’ll
want to check out for yourself by running your new program.

Upload Your HTML, CSS, and PHP


When you’re running a PHP program on your own machine, using the command
line, as soon as you’ve saved your PHP you can run it. But when you’re working with
web pages and web applications, things are a bit trickier.
When you’re building a web page, you have to upload your HTML, CSS, and any
JavaScript you’ve written to your own web server. Then, you access those files with
a browser, through a web address like www.yellowtagmedia.com/sayHello.html.
Typing that web address into your browser causes your server to supply your HTML
to whatever web browser requested the page.

20 PHP & MySQL: The Missing Manual


Running
PHP works the same way. Once you’ve written your PHP programs, you upload Your Second
them onto your web server with your HTML and CSS. Typically, you’ll end up with Program
files and directories like the following:
• Root or home directory (/). Your web root, where you put all your HTML. This
usually is the location referenced by a URL like yellowtagmedia.com/, without
any specific file after the web server name.
• CSS directory (css/). The directory where all your site’s CSS is stored.
• JavaScript directory (js/). Your JavaScript files go here. You’ll often see this
directory also called scripts/, but since PHP programs are also called scripts,
it’s a good idea to be more explicit in your naming.
• PHP directory (scripts/). Here’s where you put all your PHP programs. Again,
you could call this something more specific like php/ or phpScripts/, but more
often than not, websites use scripts/ for this directory, so following that lead
is a good habit to get into.
• Examples directory (ch01/, ch02/, and so forth). As you’re working through
the examples, you’re going to end up with a lot of PHP programs, and fast.
To keep everything organized, you should have a separate directory for each
chapter. So when you upload sayHello.html and sayHelloWeb.php, upload them
into ch01/sayHello.html and ch01/scripts/sayHelloWeb.php.

Note You don’t have to organize things this way, but if you do, all the examples you download for this book
will work without any changes. If you do change this directory structure, you’ll need to change all the references
in your HTML and PHP to CSS, JavaScript, and other PHP programs.

Now that you’ve got your HTML and PHP ready, you need to upload those files to
the right directories on your web server. You should also download phpMM.css from
the book’s website at www.missingmanuals.com/cds/phpmysqlmm, and get the
CSS in the right place as well.
Once you’ve got everything in place, your web server directory structure should
look something like Figure 1-17.

Running Your Second Program


You’ve got your HTML and CSS in the right place, and your HTML form has your PHP
program set as its action. You also should have sayHelloWeb.php in your ch01/scripts/
directory. All that’s left is to take your PHP for a spin. Open up a web browser and
go to your web server, and then add ch01/sayHello.html to your server name. You
should see the HTML you created in sayHello.html, just like in Figure 1-18.

Chapter 1: PHP: What, Why, and Where? 21


Running
Your Second
Program

Figure 1-17
The HTML and PHP files you
created are specific to this
chapter, so they belong in
ch01/. But phpMM.css is for
all the book’s examples
you’ll be building, so put
it in css/ under the root of
your web server.

Figure 1-18
More often than not, you’ll
access an HTML page rather
than a PHP program directly.
But those HTML pages will
use your PHP programs to
generate responses to your
users’ requests.

22 PHP & MySQL: The Missing Manual


Running
Type your name, and then click the Submit button. The page sends your name as Your Second
part of the form to the form’s action, your sayHelloWeb.php program. That program Program
runs on your web server, and then you should get a response back, something like
Figure 1-19.

Figure 1-19
The web browser
doesn’t actually run your
program. Instead, it asks
your server to run the
program, and that server
then gives the result of
running sayHelloWeb.
php back to the browser,
which shows you a
personalized welcome
message.

It may seem like you’ve done a lot of work just to have a web browser tell you your
name. In fact, you could probably write the same program in JavaScript if you
wanted. But now that you’ve created a few PHP programs, you should already see
how easy it is to write this sort of code.
And before you know it, you’ll be doing a lot more than telling users their names.
You’ll be talking to a database, doing advanced calculations, making decisions based
on information the user gave you and what you have stored in a database, and more.
But it all begins with a little HTML, a PHP program like the ones you’ve just written,
and the directory structure you’ve got in place.

Chapter 1: PHP: What, Why, and Where? 23


24 PHP & MySQL: The Missing Manual
chapter
Header Last

2
PHP Syntax: Weird
and Wonderful

Y
ou’ve got a couple of PHP programs running, and one of them even works
with an HTML form. But so far, you’ve just been typing code. Even though
you’ve just gotten started with PHP, you’re ready to dig deeper, and start to
understand what’s going on in that code. In this chapter, you’re going to get com-
fortable with a lot of the PHP syntax: that means learning what special words you
type into your programs, and what each one of those special words—usually called
keywords—tells PHP to do.
Fortunately, this learning doesn’t mean you can’t still build interesting programs that
run in a web browser. In fact, since almost everything that’s done with PHP involves
Web pages, all your scripts in this chapter will accept information from a Web form
and work with that information. So you’re not just learning PHP; you’re learning to
write Web applications.

Get Information from a Web Form


In sayHelloWeb.php, you used this line to get the value of a variable called “name”
from the sayHello.html web form:
echo $_REQUEST['name'];

You may remember that $_REQUEST is a special PHP variable that lets you
get information from a web request. You used it to get one particular piece of
information—the user’s name—but it can do a lot more.

25
Get
Information
from a Web Access Request Parameters Directly
Form
In fact, to see just how handy $_REQUEST really is, open up your text editor. Type
the code below, in which a visitor enters her name and several other important bits of
contact information, like her Twitter handle, Facebook page URL, and email address.
<html>
<head>
<link href="../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 2-1</div>

<div id="content">
<h1>Join the Missing Manual (Digital) Social Club</h1>
<p>Please enter your online connections below:</p>
<form action="scripts/getFormInfo.php" method="POST">
<fieldset>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" size="20" /><br />
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" size="20" /><br />
<label for="email">E-Mail Address:</label>
<input type="text" name="email" size="50" /><br />
<label for="facebook_url">Facebook URL:</label>
<input type="text" name="facebook_url" size="50" /><br />
<label for="twitter_handle">Twitter Handle:</label>
<input type="text" name="twitter_handle" size="20" /><br />
</fieldset>
<br />
<fieldset class="center">
<input type="submit" value="Join the Club" />
<input type="reset" value="Clear and Restart" />
</fieldset>
</form>
</div>

<div id="footer"></div>
</body>
</html>

Tip For more information on how HTML is used in this code, see the box below.

26 PHP & MySQL: The Missing Manual


Get
Information
from a Web
Form

POWER USERS’ CLINIC

HTML Should Be Semantically Meaningful


You may have noticed some pretty big changes in this HTML By making the HTML mean something, a browser (and other
from the simple form from Chapter 1 (page 18). In that chapter, HTML authors) know what things actually are in your form:
the form used <p> tags to break up the form labels and input labels are meant for, well, labeling things. Fields are grouped
boxes, and manually formatted the form labels with <i> tags. together with fieldset . And italic and bold are left to your CSS,
That got the job done, but it’s not a good use of HTML. just as they should be.
Anytime you’re writing HTML, you’re actually structuring your What’s really cool here is that now your CSS can do an even
page. So a form tag doesn’t really do anything visually; it just better job of styling your form. Since you’ve gotten rid of
lets a browser know, “Hey, here’s a form.” When you use tags formatting in the HTML, you can style all your form labels the
like <i>, though, you’re not describing structure; you’re telling same way—perhaps by bolding them, right-aligning them, and
the browser how something should look. That’s really not what adding a right margin of 5 pixels. The same is true of your sets
HTML is for, though; that’s the job of CSS. of fields; you might put a border around related fields, which
In this form, though, all the formatting has been pulled out. is exactly what’s going on in the CSS applied to this form. In
Instead, all the labels are identified with the label element, and fact, to see how the CSS affects these HTML elements, check
a for attribute. That identifies the labels as labels—regardless of out Figure 2-1.
how those labels end up looking—and also connects each label Truthfully, if you’re new to making your pages semantically
with the specific input field to which it matches. There’s also meaningful, it may take you a little time to get used to using
a fieldset element that surrounds the different blocks within HTML just for structure, and keeping all your style in CSS. But
the form: one for the labels and text fields, and a second for stick with it; your pages will look better, and anyone who has
the form buttons. This arrangement also provides semantic to update your pages down the line will thank you.
information: information that has meaning.

Save this file as socialEntryForm.html. To make sure your HTML is just the way
you want, go ahead and upload it to your server, in the ch02/ directory. Make sure
you’ve got the book’s CSS in the right place—under css/ in your server’s root—and
then open a browser and head over to your HTML form. You should see something
like Figure 2-1.
In sayHelloWeb.php, you used $_REQUEST to get submitted form information, and
then asked specifically for the “name” value. But with this new form, there’s a lot
more information being sent from the form.
To get all that information, you need to create a new script called getFormInfo.php,
and enter in this code:
<html>
<head>
<link href="../../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>

Chapter 2: PHP Syntax: Weird and Wonderful 27


Get
Information
from a Web <body>
Form <div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 2-1</div>

<div id="content">
<p>Here's a record of what information you submitted:</p>
<p>
First Name: <?php echo $_REQUEST['first_name']; ?><br />
Last Name: <?php echo $_REQUEST['last_name']; ?><br />
E-Mail Address: <?php echo $_REQUEST['email']; ?><br />
Facebook URL: <?php echo $_REQUEST['facebook_url']; ?><br />
Twitter Handle: <?php echo $_REQUEST['twitter_handle']; ?><br />
</p>
</div>

<div id="footer"></div>
</body>
</html>

Figure 2-1
This web form is a pretty
typical entry page for a
user to fill in. But what
happens when this form
gets submitted? You’re
about to find out, and in
fact, take control of all
this entered information.

28 PHP & MySQL: The Missing Manual


Get
Information
from a Web
Note If you want to start taking a little more control of your scripts, you can name this program something Form
other than getFormInfo.php. Just be sure that you also update socialEntryForm.html and change the form’s action
attribute value to match your own custom script name.

You can already see what’s going on here. In addition to grabbing the value of the
“first_name” and “last_name” fields—similar to getting the value of the “name”
field in sayHelloWeb.php—you’re using $_REQUEST to pull in the values the user
entered into the other form fields.
Go back to your web form, and enter your information. Then submit the form, and
you should see the result of getFormInfo.php running. Your browser should show
you something like Figure 2-2.
In fact, this is the way you’ll use the $_REQUEST variable in most of your PHP
programs:
echo $_REQUEST['FORM_INPUT_FIELD_NAME'];

Figure 2-2
Almost everything in PHP
begins with some piece of
information submitted via
either an HTML Web form
or another PHP script.

Create Your Own Variables


You may have times where you don’t want to just spit out the value of a field. Think
back to your first program, sayHello.php (the version that didn’t run on the Web).
In that program, you created your own variable:
$name = trim(fgets(STDIN));

Chapter 2: PHP Syntax: Weird and Wonderful 29


Get
Information
from a Web PHP lets you create all the variables you want. Just think of a descriptive name (for
Form suggestions, see the box on page 31), and put a dollar sign before that name, like this:
$numberSix = 6;
$thisIsMyName = "Brett";
$carMake = "Honda";

With this chunk of code in mind, go back to your new program, getFormInfo.php.
Instead of just using echo to print out the submitted information, store each piece
of information in a variable. Then you can use that information however you want,
and as many times as you want.
<?php

$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$email = $_REQUEST['email'];
$facebook_url = $_REQUEST['facebook_url'];
$twitter_handle = $_REQUEST['twitter_handle'];

?>

<html>
<head>
<link href="../../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>

<body>
<!-- Existing HTML code -->
</body>
</html>

Notice that you can create blocks of PHP code—beginning with <?php and ending
with ?>—anywhere you want. In this script, there’s currently a block of PHP before
any HTML, and then several small blocks of PHP within the big chunk of HTML. It’s
really up to you when and where your PHP goes, as long as it gets the job done.
You could have put this block of PHP between the page’s opening html and head
element, or between the head and the body elements; that choice is up to you.

Note Just because you can do something doesn’t mean you should. It’s usually best to do as much of your
PHP work as you can before you output any HTML, and then output as much of your HTML as you can in a single
place. This system keeps most of your code in one place, and most of your HTML in another place. (For more advice
on why it’s important to keep your code well organized, see the box on page 32.)
Of course, you’ll still have lots of times when you insert PHP into your HTML, as in getFormInfo.php, and that’s
okay. Those little bits of PHP fit into the HTML, and certainly don’t mix things up as much as 20 or 30 lines of PHP
stuck in the middle of your HTML.

30 PHP & MySQL: The Missing Manual


Other documents randomly have
different content
ikke synderligt ud fra den gamle, hvor Hans Maiestæt laa, s a a a t
ide tm in ds te de N ær mes te a f Ar beider ne kunde h ave s e et
h a ns H ove d ove r de n ga mle L inies B r ys tvær n, om de
e l ler s havde give t Agt der pa a . Denne Oms tæn digh ed
a n s eer j e g fo r be tyde l ig nok ti l a t a nmær ke her.« —
Andre tvivlede ikke paa, at Kongen var kommen af Dage ved
planlagt Mord.
»Natten var ualmindelig mørk,« fortæller en Grev Lieven. »Jeg
havde den Ære den Nat, Kongen faldt, at opvarte ham som Page.
Jeg tvivler ikke paa, at han er kommen af Dage ved Snigmord. Det
var næsten umuligt, at en Kugle fra Fæstningen kunde ramme hans
Hoved i en saadan Afstand og paa den Plet, hvor han stod. Jeg saae
Kongens Liig og er overbeviist om, at Saaret i Tindingen var af en
Pistol. Hvo, der har bibragt ham det, er uvist. De, der have Erfaring i
Krigsvæsenet, kjende Knaldet af en Kanonkugle; men Knaldet af
dette Skud var nærmere ved og ganske anderledes. Hele Armeen
troede, at Kongen var dræbt af en ubekjendt Haand.«[6]
Carlberg befandt sig ogsaa ved Kongens Fødder, da udefra et Skud
traf ind gjennem Hans Maiestæts Hoved, hvorved ikke den mindste
Bevægelse mærkedes undtagen, at Haanden faldt ned fra det
venstre Kindbeen, og Hovedet bøiede sig sagte ned i Kappen, uden
at det allerringeste Ryk sporedes i Legemet. Da Officererne stode
saa lavt, kunde Ingen med Vished bemærke hvor Skudet kom fra.
Den første, som nævnte Kongen død, var Generaladjutant Kaulbars.
Da han saae Kongens Hoved synke ned i Kappen, raabte han:
»Herre Jesus — Hans Maiestæt er skudt! Opsøg General Schwerin
og meld ham det.«
Carlberg løb strax nedad den gamle Approche og mødte Generalen,
der næsten aldrig veg fra Kongens Side. Da han modtog det
sørgelige Budskab, greb han Carlbergs Arm og udbrød hviskende:
»Herre Jesus!« Han ilede til Stedet, hvor Kongen endnu laa urørt og
befalede Carlberg og Capitain Posse at hente en Baare. De ilede over
Bjerget til Kongens Brædehytte. Her var Forraad af færdige Baarer,
som brugtes til at bortbære dem, der om Natten bleve skudte under
Arbeidet. Carlberg og Posse bare selv Baaren frem foran Kongens
Fødder. General Schwerin havde stillet Vagt i Løbegraven, for at
hindre Kommunikation forbi Kongens Liig. Officerernes Antal var
betydelig forøget; de stode alle tause og blege i Faklens Skin.
Generalen steg op paa Brystværnet ved Kongens Side og løftede
hans Hoved lidt i Veiret, hvorpaa han gjorde et bedrøveligt Tegn med
Haanden til de Omkringstaaende uden at sige Noget. Kuglen var
gaaet tværs igjennem Hovedet og havde draget det ene Øie indad,
medens det andet hang ud over Kinden. Liget blev forsigtig løftet
paa Baaren og tildækket med Soldaterkapper.
Adjutant Siquier traadte frem fra Mørket, som laa over Hjørnet ved
Vinkelspidsen, tog Hatten af Kongen og satte i dens Sted sin hvide
Paryk og gallonerede Hat paa Carl den Tolvtes Hoved og sørgede for,
at noget af Hat og Paryk kom til Syne under Kappen, hvilket skete
for at gjøre Kongen ukjendelig, da man frygtede for den Virkning,
som det bratte Budskab om hans Død vilde have paa Soldaterne.
Da dette var varetaget, vendte Siquier sig til Officersklyngen og
sagde med et Skuldertræk: »Historien er ude. Allons souper!«[7]
General Schwerin overlod det kongelige Liigs Transport til Lieutenant
Carlberg, der fik ti Mand hertil, hvilke han gav den Besked, at det var
en tapper Officeer, som de maatte bære forsigtigt paa den ujævne
Vei. Da Toget var kommen et Stykke frem, opdagede Folkene, at de
vare gaaede vild og befandt sig paa Toppen af en steil Bakke. Byen
var nær, hvorover de bleve bestyrtede, da man vidste, at norske
Patrouiller her holdt Vagt og saaledes gjorde det voveligt og usikkert
at trænge frem. Baaren blev sat paa Jorden og Veien langs Elven
undersøgt. Efter en kort Raadslagning besluttede man at gaa videre
ned over Bakken. Soldaterne formanedes til Forsigtighed; Carlberg
med to Mand holdt igjen paa Baaren under den steile Heldning.
Ved Uforsigtighed skete det dog, at Kongen væltede ud over Baaren
ned i Carlbergs Arme, dog saaledes, at Legemet ikke faldt heelt ned
paa Jorden; thi i samme Nu sprang en graahaaret Mand, der gik ved
Siden af Baaren og ufravendt betragtede den, frem og understøttede
Carlberg i at løfte Liget tilbage paa Leiet. Ved den heftige Bevægelse
gled Hatten og Parykken af Kongens Hoved. Maanen, som ved
denne Tid var kommen høit over Fjeldet, kastede sit klare Lys lodret
over de kjendte og elskede Træk. Soldaterne stirrede bestyrtede og
udstødte et Klageskrig.
»Kongen — Kongen!« hviskede de. »Hvad skal der nu blive af os
Alle?«
Den Graahaarede stod foroverbøiet og betragtede som fasttryllet
med et forskende Blik det gabende Saar i Ligets venstre Tinding.
»Det Hul har ingen Pistolkugle frembragt!« udbrød han heftig og
greb Carlbergs Arm. »Det er en Flænge efter en Granatstump. —
See — see selv!«
»Hvad mener Du?« sagde Lieutenanten dæmpet og rev sig løs fra
Mandens Jerngreb. »Ligemeget, hvor den dræbende Kugle kom fra.
Kongen er død, Krigen endt — Norge er tabt for Sverige.«
»Norge er frelst,« hviskede Manden og traadte tilbage i Geledet.
Norske, høirøstede Stemmer løde i Nærheden. Carlberg lyttede og
befalede barsk Soldaterne at forholde sig stille. De bleve øieblikkelig
tause, medens de med rørende Omhu tildækkede Liget og fra dette
Øieblik bare det videre med en øm Forsigtighed, som om de meente,
at deres Afgud endnu kunde føle Stødene fra den ujævne Vei.
Sørgetoget naaede uden videre Uheld til den ældre Tranché, Baaren
løftedes op over Brystværnet og ankom kort efter til Hovedkvarteret
i Tistedalen, hvor Kong Carl samme Aften havde bivaanet sin sidste
Gudstjeneste. I hans Lommer fandtes intet undtagen Gustav Adolphs
Portrait og Bønnebog.
Klokken eet om Natten blev Carl den Tolvtes Liig ført ind i den Hytte,
hvor han pleiede at udhvile sig. Idet Baaren naaede Huusdøren,
traadte den samme graahaarede Kæmpe hen til den, blottede sit
Hoved og stirrede i det klare Maanelys endnu en Gang paa de
kongelige, stivnede Træk, som om han forgjæves søgte Svar paa et
Spørgsmaal, en uløselig Gaade, som Fremtiden aldrig skulde opklare.
Bjørnstad — det var ham — huuløiet, hentæret og eensom, bøiede
et Knæ mod Jorden, idet Liget blev baaret forbi ham.
»Ikke bleve vi dine Nordmænd; men Du blev vor, Carl af Sverige!«
udbrød han med høi Røst. »Du store Døde! nu først hilser jeg Dig
velkommen til vort eget, frie Norge!«
Da Baaren forsvandt i Hytten mellem tændte Fakler og sørgende
Soldater, strakte den eensomme Mand Hænderne mod Himlen med
et Udtryk saa seiersstolt og jublende som i Bevidsthed om en
veludført Gjerning — som om han i dette Nu gjennem sin høire
Haand følte sit hele Lands Befrielse fra fremmed Aag og Fare.
Samme Nat en Time senere lød en Steentorstemme hen over
Stortorvet i Frederikshald:
»Norge er frelst — Kong Carl er død!«
Raabet blev hørt af Mange, uden at Nogen vidste, hvorfra det kom;
det blev troet, uden at Nogen kjendte den vældige Røst, der
slyngede Glædesbudskabet over Staden. Det fløi som en Løbeild
gjennem Gaderne. Der lød et Jubelskrig, heftigt, aandeløst.
Kirkeklokken, der endnu hang i en Galge over den Kjælder hvor
Gudstjenesten maatte holdes siden Kirkens Brand, klemtede som til
Helligfest — et Befrielsens Skrig efter det aarelange Rædselens
Mareridt lød fra det ængstede, forpinte Folkebryst: »C a r l den
To lvte e r død!«
I samme Time den svenske Konge faldt, standsedes alle Arbeider i
Løbegravene. Den følgende Dag holdtes Krigsraad. Det blev
besluttet at hæve Beleiringen, og at Hæren ufortøvet skulde drage
tilbage til Sverige. Den 20. December havde alle Svenske forladt
Norge. Af General Armfeldts nordenfjeldske Hærafdeling naaede
næppe 500 Mand tilbage over Fjeldene. Henved 9000 Mand bukkede
underveis under for Vinterkulde, Sneestorme og Hunger.
DEN STORE FRED.
Der gik flere Aar. Meget forandredes i Frederikshald og Omegn.
Staden reiste sig af Asken, Handelen blomstrede, Skibsfarten tog til,
et freidigt, stærkt og selvfølende Folkeliv udviklede sig hurtigt i den
unge Stad, der var skudt frem af Storbedrifter, omgivet af en velvillig
Samtid, Gjenstand for Udlandets Beundring, Tidens Kjælebarn.
Det gik nu her, som det oftest gaaer, dèr hvor de store Storme
rensende fore frem: et sundt og rankt aandeligt Liv blev Særmærket
for Frederikshalds Borgere. De fordrede Retfærdighed og gave
Retfærdighed, Lys og Skygge fordeeltes af den almindelige
Retsbevidsthed. Og den var klarøiet i det stærke Lys, som nu laa i
Luften.
Saaledes gik det til, at der blev ryddet op i meget gammelt og
forgroet. Megen Overvurdering og tidligere Vrangvillie kom paa
Retfærdighedens Vægtskaal, saaledes ogsaa Dommen over
Bjørnstad fra Fossegaarden. Først begyndte Rygtet at fortælle om
hans frivillige Kamp i Frederikshald under Svenskernes Indfald,
skjøndt Borgerne haanlig havde tilbageviist ham fra deres Række;
dernæst blev hans eneste Søns Fald under Forsvaret omgivet af et
smukt og romantiskt Skjær; om Hustruens Ulykke og Død vidste
man ogsaa meget rørende at fortælle, og endelig var det mærkelige
indtruffet: efter at Bjørnstad havde forladt sin Hjemstavn og var
forsvundet fra Egnen, blev Byens Tømmer borte i Elvedragene
ovenfor Staden i endnu større Maalestok end i Bjørnstads Tid. Han
havde saaledes baaret Skylden for Andres Ugjerninger.
Man havde nu erfaret, at Bjørnstad levede oppe i en øde Klippeegn
ovenfor Sarpfossen. Han havde tilligemed sin gamle Søster Ellen
opslaaet en Bolig mellem de eensomme Fjelde og boede der i en
afsides Hytte. Det gamle Søskendepar var her bleven et Forsyn for
Fattige og Syge, der kom langveis fra til Eneboerne, for at forlade
dem trøstede og glade.
Det var dog endnu ikke disse forskjellige Kjendsgjerninger, der
bevirkede Omslaget i Folkestemningen overfor Bjørnstad og gjorde
hans Navn kjendt og omtalt. Der var endnu et Rygte i Omløb, et
ubestemt Sagn, som satte ham i Forbindelse med Kong Carls Fald,
der bragte alle Hjerter i Frederikshald til at banke stærkere, en
Beskyldning, der i sig selv for Staden rummede det Høieste, en
Forbrydelse, der lyste som en Fædrelandsbedrift af største
Betydning, et Rygte, der ikke havde nogen bestemt Hjemmelsmand,
og som dog blev ved at leve, at svulme, til det antog Karakteren af
Forherligelse og Tilbedelse af sin Gjenstand.
Hvad der sagdes var slet og ret, at Bjørnstad havde fældet Carl den
Tolvte.
Man vidste med Bestemthed, at Bjørnstad hiin Nat befandt sig blandt
Arbeiderne i Løbegravens Sidelinie, da Kongen faldt; man vidste, at
han allerede under Indfaldet 1716 havde sat sig det store Maal at
fælde Kongen i aaben Kamp for at befrie sit Land, og man vidste nu
fra Jørgen Halvorsen, at Bjørnstad var en syg og nedbrudt Mand, der
ofte i Febersyner anklagede sig selv for at have fuldbragt den store,
tragiske Bedrift.
Tilsidst var det Øieblik kommen, da den offentlige Mening slaaer
over i sin Modsætning, taler høit og høiere, bliver Folkets Røst, Guds
Røst, og det blev besluttet i en Forsamling af Byens Borgere, at der
skulde gjøres noget for Bjørnstad, at han skulde hædres, udnævnes
til Æresmedlem i det Colbjørnsenske Fricorps, hvilket han en Gang
forgjæves tilbød sin Tjeneste, kort sagt: Bjørnstad skulde udmærkes
med et eller andet, hvad det nu kunde blive til. Han var dog en
Mand fra Frederikshald, deres egen, det maatte fremhæves nu.
Medens dette Omslag fandt Sted nede i Staden, levede Gjenstanden
for al denne Velvillie sit eget Liv i en vild og skovrig Fjeldegn norden
for Sarpfossen, tre Mil fra Frederikshald. Denne Fos er hverken saa
høi eller bred som flere andre af Landets Fosse; men den ansees
med Rette for et af Norges skjønneste og mægtigste Vandfald. Især
udmærker den sig ved den overordentlige Vandmasse og
forfærdelige Kraft, hvormed den skyder sig frem, beriget ved utallige
Vandaarer fra det vilde og skovrige Terrain.
Bjørnstad og hans Søster Ellen levede heroppe i Ødet i uforstyrret
Fred og uddeelte nu med rund Haand Udbyttet af deres Livs
Indkomst til Livets trætte Arbeidere, som langveis fra tyede herop
om Hjælp og Raad. Vinter og Sommer var Stien op til Hytten banet
og traadt, og der gik aldrig Nogen forgjæves.
Faster Ellens forvitrede Skikkelse havde rettet sig i de forløbne Aar.
Øinene lyste med bjørnstadsk Ild; en bruunrød Sundhedslød over
det magre Ansigt røbede, at Livskraftens Kilde atter sprang i hendes
Bryst.
Der var nok at skaffe om i Fjeldhytten. Køernes Mælk stode i lange
Bøtterækker paa Sæterhylderne, Osten laa i Lager, tørrede
Urteknipper hang under Loftsbjælkerne. Faster Ellen besad det
skarpe Blik og den lykkelige Gjætte- og Slutteevne, der gjør forfaren
i Lægekunst. Om Vinteren snurrede Rokkehjulet, Ulden kartedes,
varme Sokker og Trøier og alskens andre varme Sager laa beredte
for de Trængende.
Midt i al denne Travlhed fløi Faster Ellens Blik jævnlig forskende over
til Bjørnstads høie og vaklende Skikkelse, naar han uddeelte milde
Gaver med et Blik, der røbede, at det ikke alene var Haanden, som
gav, men Hjertet, der glædede sig over at kunne give.
»Nu op med Panden, Broder!« lød det ofte barsk og opmuntrende;
»Han forstod den bedste Kunst, han, som levede for en anden,
levede ei sit Liv omsonst.«
Faster Ellens Tale faldt ofte i Riim, uden at hun egentlig selv vidste
derom.
»Bølgeskvalpet gaaer i Takt, som Stormen det vil,« sagde hun en
Gang, da Jørgen Halvorsen gjorde hende opmærksom herpaa.
»Kom nu og hjælp med, Broder,« sagde hun til andre Tider i de
første Aar af deres Eneboerliv, naar Bjørnstad i Timer lukkede sig
inde i sin Stue og sad og stirrede frem for sig med en knyttet Haand
paa hvert Knæ, mens Tanker gravede og gravede i hans Indre og
kun naaede at undergrave hans egen Kraft. Saa reiste han sig
brummende, greb Karterne eller Strikketøiet og bandt Hoser, mens
Vinterstormen ruskede i Hytten, og Sneeskredenes Drøn lød rundt
om udenfor. Der sad de to gamle Skibbrudne, kastede op paa dette
Fjeld fra Livets Brænding, graanede i Sjælens Bedrifter, medens de
nu med det sløvede Høgeblik anstrengte sig for at indhente en
løssluppen Uldgarnsmaske i det flakkende Lampelys, medens
Mindernes Skred drønede gjennem deres Indre. Saa hændte det, at
Bjørnstad utaalmodig slængte Strikketøiet over til Søsteren og forlod
Hytten for at gaae ud i Vinternattens store Syner. Eller han vandrede
langt over Fjeldet til de Hjem, hvor han vidste, der trængtes.
Aarene havde ogsaa i hans Sind bragt Forandring: Den store Fred
var seen om at komme til ham, og den kom ikke pludselig, ikke uden
Kampe. Lidt efter lidt var dog Kjærlighedens store »Du og jeg«, »Du
fremfor mig« gaaet op for ham i sin Vælde, og i dette klare Lys fra
oven stod hans Ungdoms Stræben og hans Manddoms Kamp for
ham grelt og skjærende i den hele Selviskhed og Egenkjærlighed,
»Jeg imod Dig«, »Jeg over Dig, over Eder Alle«. Hvornaar dette Lys
begyndte at skinne, vidste han ikke selv. Maaskee var det
Eensomheden, som maa til, for at det Store kan trives, og Læsning;
thi Bjørnstad læste meget, og hans lille Bogsamling indeholdt det
Bedste af udenlandske og indenlandske Værker.
Tilsidst forstod han alle disse Jordelivskampe med de store Ideer
som Banner og et lille »jeg selv« som Bannerfører. En dyb
Medlidenhed greb ham for de Mange, der endnu stred og led i
Uklarhed dernede. Det maatte saa være; han forstod, at det hele
Myretuearbeide maatte forrettes, noget for og noget imod, noget
skarpt, andet blidt, noget beskt og noget sødt, for at skaffe sundt
Blod til det Hele og alt, hvad der ellers maatte til, for at det kunde
holde sammen. — Af og til gik han ud til det nære Fossefald og
stirrede ned i de skummende Hvirvler; oftere gik han ud paa Pynten
med den vide Udsigt nedover. Her blev han staaende i Timer, et
sælsomt Monument, forvitret af Tiden, endnu kæmpemæssigt at
skue. Saa kunde han en Gang imellem strække Haandfladen ud,
vugge den sagte op og ned, som om han stedte noget til Hvile, og
vendte hjem støttet til sin Stav med den skaldede Isse hævet og det
hvide Skjæg og Haar bølgende i Vinden. Lidenskabernes Tid var
omme; det afgjærede Stof laa klaret i hans Tanke. Det, de kaldte
Stort dernede, Fremskridt, Magt, Mit og Dit, selve Landegrændsen
mod det »Udenlandske«, Fædrelandets Begrændsning til en bestemt
Plet Jord, altsammen blev heroppe, omgivet af den utilhugne Granit i
det Eviges Lys, saa smaat, at det ikke var til at øine.
Ogsaa Sorgen over Maris Død, der havde knuget Bjørnstad til
Fortvivlelse i de første Aar, var mildnet; han vidste, at nu var hun
dèr, hvor hun hørte til, og forenet med sit Kjæreste. Sønnens Død
var ham hovedsagelig en Kilde til Glæde. Drengen havde aldrig i Live
været ham saa dyrebar som nu; det var, som om han havde ofret sit
Land det Bedste, han havde, en reen, ung Kraft, en Blomst i
Udspring, der aldrig vilde tørres hen i Storme.
Alene hans Livs store Gjerning, den, i hvilken hans hele Væsen
higede efter at hvile ud, kunde han ikke komme til Ro med, den
Hovedgjerning, der er enhver fuldbaaren Personligheds Hensigt, det
store, beroligende »Derfor« paa Livets »Hvorfor« gled fra ham, hver
Gang han vilde gribe den og gjøre den til sin.
Kong Carls Død var hans stadige Tanke. Javist, han var i Løbegraven
hiin Nat og fast besluttet paa at dræbe sit Lands Fjende. Javist
havde han hævet sin Pistol og skudt og seet Carl den Tolvte synke
sammen og følt sit Land befriet i samme Nu.
Snigmorder, han? Bjørnstad? — Javist, han havde i Mulm og Mørke
hævet sit Vaaben mod Kongen af Sverige; men han havde med
Glæde aabenlyst bødet med sit Liv for den Bedrift. Snigmorder? —
Nei, han havde gjentagne Gange søgt Heltekongen i aaben Kamp
med blottet Bryst — forgjæves. For Bjørnstads Fædreland var denne
Helt et farligt Kryb, der ved Nattetid gravede sig ned i dets Jord, for
som en Slange Tomme for Tomme at bugte sig fastere om Fæstning
og Stad. Et fjendtligt Kryb knuser man under sin Hæl, naar man seer
det løfter Braaden mod Ens Kjæreste, naar og hvor man kan.
Snigmorder? Nei, nei! — Bjørnstad hævede sit Hoved. Han havde i
et kongeligt Nu følt sit Lands Frelse gjennem sin høire Haand; da var
det, som om Fjeldene rundt ham klædte sig i straalende Farver, som
om Luften, han aandede, blev stærkere og mere balsamisk.
Men i en anden Time kom andre Tanker, en Tvivl, der sjeldent lod
ham i Ro, og han havde en Følelse af, at han selv gled ud i
meningsløs Taage, at Klippegrunden forsvandt under hans Fødder, at
han drev nedover uudforskelige Strømme, for at forsvinde, og der
lød intet Svar over til ham, naar han i Nattens Time kastede sig paa
Leiet og spurgte og spurgte, mens de nagende Tvivl steg.
Ja, var det ham, der havde fældet Kong Carl? — Det forekom ham,
at han havde seet Kongens Hoved allerede synke ned i Kappen i det
Øieblik, han hævede sin skudsikre Pistol og trykkede af. Saaret, som
han nøie havde undersøgt i Ligets Tinding, kunde ingen Pistolkugle
have frembragt, Kardæskregnen var forfærdelig — og dog — og
dog! Han sendte Raab paa Raab efter Sandhed ud i sin Eensomhed;
men der kom aldrig Svar. Tilsidst tog denne Grublen sygelig
Overhaand og medførte Hallucinationer; vaagne Febersyner forfulgte
ham og drev ham rastløs fra Sted til Sted.
Faster Ellens vagtsomme Øie hvilede ofte spørgende paa ham. Han
undgik enhver Fortrolighed i denne Sag. De to Søskende talte
overhovedet ikke meget sammen; det behøvedes ikke for at forstaa
hinanden. Deres Fortid eiede ikke Ord, deres Fremtid behøvede
ingen. Deres Indre var sammennittet ved det samme Livsindhold; de
gave hinanden trofast Haandsrækning, og saa gik det, som naar et
Heiseværk er i Gang: hvor den ene slap det seige Tag, greb den
anden fat, medens Minderne lagde Opsangen til.
En Dag sad Bjørnstad sammensunken udenfor Hyttens Dør. Ellen
saae gjennem den lille Rude, at han hævede Hovedet fra Brystet og
stirrede over mod Klippevæggen. Hans Øine udvidedes, hans Haand
strakte sig afværgende frem, medens han reiste sig. Ellen gik ud til
ham og lagde Haanden paa Broderens Skulder.
»Du bærer paa en svar Hemmelighed, Bjørnstad,« sagde hun.
»Betro Dig til mig. Naar tvende Venner blot enes ret, gjør fire
Hænder det Tunge let.«
Bjørnstad syntes ikke at høre hende. Han vedblev at stirre mod
Klippevæggen med stive, skjælvende Træk.
»Seer Du Hovedet derovre paa Klippeblokken?« hviskede han.
»Hans, Kongens? Seer Du hans Øine, de klare, kongelige? De følge
mig overalt, Dag og Nat. — Seer Du?« vedblev han og knugede
Søsterens Arm. »Seer Du? Nu synker det ene Øie tilbage dybt i
Hulingen, og det andet skyder sig frem, nedover Kinden, og stirrer
herover og lyser som Ild — Vent!«
En glødende Rødme gled over Bjørnstads Pande. Han strakte
Haanden om bag Døren, rev Bøssen ned fra Knagen, sigtede
omhyggelig, mens de hvide Haar klæbede sig om hans Tinding. En
Krudtsky bølgede over mod Klippestykket, og Bjørnstad sank
sammen; store Sveddraaber perlede over hans Pande.
»Havde Du tusinde Liv, Carl af Sverige, jeg tog dem alle!« udbrød
han med brudt Røst. »Hvad vilde Du her hos os?«
Ellen stod fasttryllet til Stedet. Nu forstod hun disse Skud uden
synligt Maal; Kuglerne havde allerede mærket Klippen derovre, altid
paa samme Sted. Hun rystede paa Hovedet; for dette Onde hjalp
ingen af hendes Urter, og hun sendte Bud efter Jørgen Halvorsen.
Han kom, og de to Mænd sade ofte længe sammen, mens Bjørnstad
hørte til, og Jørgen talte aabent og eenfoldigt om Tingene. Eller han
tog sin Fidel og spillede af de gamle Folkesange, meest dog
Moderens Vuggevise, der ogsaa havde lydt for Bjørnstad i hans
Barndom. Bævende og blide Toner løde i den stille Fyrreskov. Saa
hændte det, at den gamle Mands Øine sank sammen, og Jørgen sad
i Timer og ventede. Men saae han Bjørnstad aabne Øinene, lod han
paany nogle Takter glide frem, og Morbroderen smilede og faldt atter
i Søvn.
En Aften sov Bjørnstad længe. Myggene summede om ham; Jørgen
sad og viftede dem bort og betragtede sørgmodig det gamle,
karakteristiske Hoved, der allerede syntes at sove den evige Søvn.
Da Bjørnstad vaagnede, saae han paa Jørgen uden Overraskelse,
uden Sindsbevægelse, vendte saa Blikket opad.
»Aftenstjernen er nok høit paa Himlen, ja, saamænd er den det. Saa
er min Tid kommen; nu staaer min Sol op, og de komme til mig, alle
dem, som ere borte, henne — Drengen er ikke død og hun ikke
gammel, naar de møde mig mellem Træerne, og de blive længe hos
mig. — Bøi Dig, bøi Dig, Broder! sagde Søster Ulle. Javist bøier jeg
mig for Eder Alle, I Stærke og Store i Følelsen, mens jeg var saa lille
i min indbildte Manddom. — Hører Du Kilden, som siver bort
derhenne gjennem Mosset?« vedblev han lidt efter. »Den risler med
Liv, Liv, der aldrig rinder ud ligesom mit eget og — Kongens — —«
»Hvorfor bryder Du dit Hoved med al den Tvivl og Uro, Morbroder?«
spurgte Jørgen. »Jeg veed, at den Konge hviler Dig svart paa Sinde;
men hvad Magt ligger der vel paa, om det er Dig eller mig eller en
anden Nordmand, der skjød ham? Det var et Stykke fædrelandsk
Arbeide, der maatte forrettes, for at vi kunde faae Fred — og saa fik
vi Fred, og Norge blev frelst, og det var det, som det kom an paa.
Der er jo ikke en levende Sjæl, som spørger efter Gjerningsmanden.
Jeg siger som de Andre: det var et Stykke godt norsk Arbeide, der
maatte forrettes af en Nordmand, og det blev forsvarligt besørget.
Derfor synes nu mig, at Du som en gjæv norsk Mand ikke har mere
Grund til at være stolt eller bedrøvet over, hvad der skete den Nat,
end alle vi Andre Nordmænd, for jeg skal sige Dig: den B edr i ft
h ører nu os Al le ti l; den er Fædrela ndets.«
Bjørnstad lyttede til denne eenfoldige Tale, medens et forklaret
Udtryk bredte sig over hans Træk, og han nikkede gjentagne Gange.
»Javist, den Bedrift hører nu Fædrelandet til,« hviskede han. »Større
Maal findes ikke for nogen Mands Bedrift, og hjulpne bleve vi Alle,
hvem der end fuldførte den.«
Der faldt som et Bind fra Bjørnstads Øine; det store Broderskabs,
Alkjærlighedens Lys gled atter hen over dette sidste Mørke i hans
Sjæl. Han reiste sig og blev seende fra samme Stund. Atter her
havde det saaledes været Selviskhedens, det stærke »Jeg selv«,
»Jeg« i Modsætning til »Dig«, »Jeg over Eder Alle«, der havde villet
tvinge ham frem til at eie denne Storbedrift for sig selv alene; derfor
havde han ikke kunnet finde Rist eller Ro; thi Anger over sin
veloverlagte Handling følte den villiefaste Mand ikke; hans nagende
Uro havde blot været Mistvivl om ikke at kunne tilstaa sig selv,
Bjørnstad fra Fossegaarden, Stormagtsbrynden: ikke at have levet
forgjæves, Følelsen af ikke at glide ud i det tomme Rum som en
unyttig Ting — den selvforherligende Ret til at kunne slaa sig paa sin
Personligheds Bringe, han, Bjørnstad, Martyren, og svare sig selv
dette falske »Derfor« paa Evighedslivets »Hvorfor«. Som om det i
det Hele taget var denne Slags Storhedssvar, det kom an paa, naar
en Gang Herren kalder sin Tjener til Regnskab for, hvorledes han har
forvaltet de tyve, de ti — det ene betroede Pund?
Veien til den store Fred var endelig funden for Bjørnstad, og han
forlod den ikke tiere. Lyset blev ved at vælde frem. Han grublede
ikke længer, han gravede ikke længer efter Gaadens Løsning i sit
eget uredige Skyggerige, hvor de halvfærdige Drømme, Drifter og
Haab havde koglet og kogt alle Slags dæmrende Muligheder. Det
ene Menneske var jo det andets hjælpsomme Broder. Der var nu
ikke noget Skyggerige længer; thi dèr, hvor dette Lys lukkes ind,
dræbes al lyssky Svamp og fremmes til Fuldbaarenhed hver Spire,
der fødtes til det Evige.
Mens dette Omslag fandt Sted hos Bjørnstad, og hans storttilhugne
Aand i Ro og Klarhed stærkere og stærkere higede imod som en
upersonlig Velgjerning at glide over i sit Folk, at gaa op i dets
Velfærd, gik det jævnt ned ad Bakke med hans Kræfter. Den fordum
saa mægtige Skikkelse laa nu oftest i Høstsolens skraa Straaler
udenfor Huusdøren, hvorfra han kunde see Stien forsvinde i Dalen.
Bjørnstad saae ofte nedover med milde Øine; oftere saae han dog
langeligt opad; han begyndte nu at længes andet Steds hen.
Den slanke Birk stod allerede bladløs ude paa Skrænten; den havde
givet Efteraarsvinden sin sidste Guldskilling, men svang lige let sine
tynde Grene for de t. Det gulnede Løv var til Høstmaneuvre; Vinden
drev det rundt om Bjørnstad i stedse snevrere Svingninger: høire om
— venstre om — og det kunde Exercitsen. Efteraaret og Hvilen var
for Døren. Enebærbuskens mørke Spids hævede sig over Lyngen
som et sørgende memento mori; tillige som et forjættende
Fingerpeg mod Himlen.
Bjørnstad skyggede med Haanden for Øinene. En lille Skare Mænd
kom frem paa Stien nede fra Dalen; de arbeidede sig møisommeligt
op ad den stenede Vei. Nogle nysgjerrige Geder sprang fra
Klippeblok til Klippeblok; Køernes dybtstemte Klokker løde gjennem
den harpixsvangre Høiluft.
Det var Peder Colbjørnsen, Foged Wexelsen, Kjøbmand Wærn og
flere andre af Byens ansete Mænd, som denne Høstdag havde
besluttet at besøge Bjørnstad og bringe ham Stadens Tak og
Udmærkelse.
Da Mændene naaede op til Hytten, havde Bjørnstad reist sig og stod
støttet mod Trævæggen. Hans hvide, blottede Hoved med de furede
Træk indgjød de Kommende den Ærefrygt, som omgiver Eneboeren.
Da de Fremmede naaede op, traadte først Raadmand Wærn frem for
Skaren, lod sit blomstrede Silketørklæde løbe rundt indeni Hatten,
aftørrede Issen, rømmede sig og sagde:
»Vi Borgere fra vor gode Stad Frederikshald hilse Dig, Bjørnstad. Din
store og modige Gjerning er rygtedes iblandt os, og vi mene at
skylde Dig vor Tak, mens Du i Stilhed og Beskedenhed har trukket
Dig tilbage fra din velfortjente Belønning. Derfor have Kvinderne i
Frederikshald besluttet at sende Dig dette Udmærkelsestegn, en
Orden, de ere traadte sammen for at stifte og uddele til udvalgte
Mænd, der i Særdeleshed som Du have gjort sig fortjent af Kvinden
og Hjemmet[8]. Alene for din Skyld have vi vandret den lange Vei
herop i Ødemarken.«
Bjørnstad modtog det fremrakte Udmærkelsestegn, et skinnende
Kors. Han saae længe og taus derpaa.
Faster Ellen var traadt hen ved hans Side. Hun rystede paa Hovedet.
»Er det for den Gjerning i Løbegraven, at de sende Dig et Kors?«
spurgte hun barsk.
Bjørnstad nikkede sørgmodig. Ellen tog sagte Korset af Broderens
Haand, kyssede det ærbødigt og holdt det over sit Hoved.
»Vor Frelsers Storkors, det skal straale klart og reent fra Himlen, det
maa ei lue naglet til en Fjendes Bryst i Stimlen!« udbrød hun med
skjælvende Træk og dæmpet Røst.
»Fjende, Søster?« sagde Bjørnstad bebreidende og værdigt. »Nei,
ikke Fjende, kun Synder, en stor, men omvendt Synder.«
»Du dyrebare Broder!« hviskede Ellen og støttede sig til hans
Skulder. »Gjør altid Ret, bliv ikke træt, sagde vor Moder. Heroppe
ingen Løgne — ikke Frelserens dyre Kors for Mørkets geniale
Gjerning.«
Peder Colbjørnsen, der havde opnaaet megen Anseelse og
Berømmelse i sin Fædrenestad og langt udenfor, traadte nu frem
med blottet Hoved.
»Saa sees vi da igjen, Bjørnstad!« udbrød han venligt og rakte
Eneboeren sin Haand. »Denne Gang kommer jeg som Udsending fra
vor Stad. Hilsen og Tak for dine heltemodige Kampe 1716, da din
tapre Søn faldt, og for din store og uegennyttige
Fædrelandskjærlighed, der i Mulm og Mørke drev Dig ud for at fælde
vor Fjende og redde vort Land. Vi kalde Dig en af vore bedste
Mænd. Derfor have Borgerne i deres Raad besluttet at overrække
Dig dette Diplom som Æresborger i vor Stad.«
Bjørnstad hørte paa denne Tale, værdig og ubevægelig. Da
Colbjørnsen tav, og han modtog Diplomet med Byens store
Vildmandssegl, gled et Smil over hans Ansigt.
»Tak, I gode Mænd fra Halden,« sagde han med mild Røst. »Hav
Tak, at I kom herop til mig, mens det dog er mig, som i Tanken
mangen Gang kom ned til Eder. Jeg skylder Jer jo Alle Afbigt for saa
meget fra mine syge Aar — den Gang, jeg var saa stærk.«
Der gled en glødende Rødme op over Bjørnstads Ansigt, mens han
traadte frem; hans krogede Skikkelse syntes at voxe i Kraft og
Sikkerhed. Han kastede Hovedet tilbage og strakte Borgerne begge
Hænder i Møde.
»Ja, ret af Hjertet Tak, I gode Brødre, at I kom til mig, nu, det lider
mod den lange Reise. Min Sjæl glædes festligt ved dette Møde. — Er
denne Stund mit Livs store Opgjør, da er den velkommen. Saa hører
Alle, hvad jeg nu maa vidne: Al min Kamp imod Eder var Selviskhed,
alle mine Veklager over mit Lands og mit Samfunds Usseldom var et
umodent Sinds utøilede Selvgodhed, saaret i sin Forfængelighed,
ude af Stand til at underordne sig Eders Love, de urgamle, evigunge,
der rummer Alt og Alle, og som giver Plads for Alt og Alle. Jeg
gjærede og bruste over af egen Retfærd og Livskraft, troede jeg. Ak,
det var blot indbildsk Overmod, min egen Storhedsfølelse, som skar
mig bort fra Eder Alle, mens jeg af bare Manddom fortærede min
egen og Mines Lykke. Nu ligger det Hele hen i Klarhed. Jeg kunde
ydmyg knæle paa Stortorvet og udraabe min Vildfarelse for den hele
Stad; men I vilde ikke forstaae mig. I leve dernede i de trange
Gyder. Det er heroppe i Naturen og Eensomheden, at der bliver slig
Vennefest i Sjælen.«
Bjørnstad holdt inde og strøg sig med Haanden over Panden. Han
var atter det gamle Urmenneske; Røsten steg, selvtænkte Tanker
søgte frem, klædte i Skum og Fraade, i egne Ord.
»I see saa vist paa mig, I Kjære? Ja, saaledes er det blevet inden i
mig. Den Bjørnstad, I ere ude efter, han er ikke mere. Jeg siger Jer:
ham, I søge, han er ikke mere. — Men hvem er I selv? Jeg seer
iblandt Eder de Raadsherrer, som en Gang vare mig haardest. I er
det Hele dernede, maaskee det bedste af det Hele; men hvad er saa
det Hele? En Stump af det store Verdensrige. Jeg saae det igjen nys,
da jert Tog bugtede sig herop ad den stenede Vei. Verdens Samfund
er som Kæmpeslangen, Midgaardsormen, der omslynger Alt og Alle.
Er en af os saa stærk, at han kan gribe Kolossen ved Struben, ryste
Uhyret, holde det ud fra sig i stiv Arm en halv Menneskealder — et
Secund af Evigheden, — hvad saa? — Længer holder vel ingen af os
ud, mens Dragen pruster os over med sin Fraade af det
tusindtungede Gab, blinder vort Syn, hidser vort Blod, kvæler vort
Aandedræt, suger os til sig, Tomme for Tomme, velbehagelig. Det er
af os, de Stærke, han lever sig mægtig, det er os, de
Modstandskraftige, der gaaer over i hans Væsen, bliver hans nye
Nakkehvirvler, blot paa en heel anden Maade, end vi i vor
Ungdomsruus og Overmod drømte om, og tilsidst, naar vort Blod er
drukket, og vor Sjæl er flydt ud i Handling, naar vort Livs
Hovedgjerning som Sommerfuglen er flagret bort fra det fortærede
Hylster for at blive Andres Eie, naar vi selv, vort Legeme, ligger hen
som det knækkede Rør, naar vi endelig begribe, at netop saaledes,
som det gik, maatte det gaae, kun saaledes skeer os fuld Ret, idet vi
leve op i vor Bedrift, bliver en sund Bloddraabe mere i det Heles
Aarer, medens Midgaardsormen voxer sig ung ved altid yngre
Nakkehvirvler, aldrig bliver gammel, mens den ruller sine Ringe
videre, bredere, pisker alt om sig i Skum og Fraade, roder unge
Modstandslystne frem, suger ny Kraft af det sidste Nye, slænger det
ældste fra sig som overlevede, visne Haleled — ja, mens det Hele
ringler fremad, fremad mod Tidernes Evighed med de nyeste
Stridsmænd mellem Kløerne, saa lyster det Kæmpeslangen stundom,
naar halve Sekler ere svundne, at rode et eller andet Skelet frem af
Glemselen; saa er dens Fagter anderledes, saa basker den med
Halen, kaster sig i Støvet, pryder vort indfaldne Bryst med
Udmærkelser, sætter os til allersidst i brede Steenkister og hugger
vore Billeder udenpaa — for at vi selv kunne ligge Steenlig som vore
store Sorger derude i det Svundnes blide Maanelys. — Ja vist, I
komme til os, naar vi ikke længer have Brug for Jer. Hvor var I
henne, I dèr, da jeg trængte saa haardelig til Jer Medfølelse, da jeg
var ung og blød og tillidsfuld og higede ind til mit Folks Hjerte? —
Hvem spyttes der nu paa dernede? Hvis Sjæl pisker Verden nu
blodig? Hvem seigpines nu under Uforstand, vaander sig under
Haanens Svøbe? Siig, hvem tømmer nu Livets bitreste Skaal? — En
Landsmand, tænker jeg, en Broder, en Helt, der stinges ihjel, en
Kraft, større end min. Jeg blotter Hovedet for ham og hilser ham
velkommen heroppe i min Eensomhed.«
Bjørnstad stod opreist; mægtig og ærefrygtindgydende. Han
slyngede disse sidste Sætninger ud med stigende Kraft. Hans
Stemme rullede endnu en Gang som en Torden mod Fjeldvæggen;
den sidste Rest af aarelang, opsamlet Bitterhed svandt maaskee bort
i dette Sjælens Smerteraab. Han strakte Haanden ud som en Seer;
hans Blik luede atter med Bjørnstadsk Kraft, medens Borgerne stode
tause, lyttede, saae paa hinanden, nikkede og lyttede igjen.
Foged Wexelsen alene gjorde et hemmeligt Tegn mod sin Pande og
rystede deeltagende paa Hovedet, medens Bjørnstad vedblev:
»Javist, jeg seer det derude i den store Verdens Fremtidstaage.
Ormen bugter sig endnu dernede, almægtig, suger og veirer og
finder og fortærer, groer i Kræfter, i Viisdom og Herlighed. Opad,
opad, bugtes det Hele i Egenkjærlighed, Adskillelse, Fjendskab og
Viisdom. — Ha, var jeg ung en Gang til, saa fik den Midgaardsorm
mig at fortære endnu en Gang, ti Gange. — Javist, jeg seer det
derude i Fremtidstaagen. Det er ikke længere os, de Enkelte, der
fortæres. Da ordnes de store Modstandsmasser af
Fremskridtsaanden, af Oprørsgeniet, for Uhyrets Gab, og Masserne
knuses, forsvinde, fordøies, blive de nyeste Nakkehvirvler. Alt, alt
maa med, intet udenfor. Mægtigere og mægtigere løfter den sin
Nakke mod Himlen, løfter tilsidst hele Jorden, hurtigere og hurtigere,
fremad, opad, til Alt er gaaet op i dens mægtige Kæmpelegeme, til
den sidste Modstand er suget ud, til det Hele selv gaaer i
Steenkisten. Da, først da groer maaske det store Vennemenneske
frem i Freden, større i Broderskab, mere fuldkomment, end vi nu til
Dags ere. — Ja, jeg synes, det er saa grumme galt fat med Jer Alle
dernede i Soden og i Asken. Hør det, lær det, forstaa det, og det
skal være den eneste Bedrift, jeg gider tage med herfra. Kunde jeg
med fulde Fjeldlunger raabe det ud, saa det rungede over hele
Verden: Luk jeres Døre og Vinduer op for Broderskab og Venskab,
bøi Jer selv i Strenghed, bøi Eder i Ydmyghed for hinanden, bøj Jer i
Kjærlighed ind til hinanden, først da skyde de tusinde Glæder op om
Jer og blive store under den blaa Himmel, som fremkaldte dem, først
da lærer Du at føle saa reent, saa stort og sandt, at vi blive de
lykkeligste af alle Lykkelige, saa lykkelige, som Ingen veed det. Bøi
Dig, bøi Dig mod Jorden, saa drages din Sjæl opad, for saa komme
de store Syner til os med Livets Fest, den store Fred, — Guds Fred.«
Bjørnstads Hoved laa tilbagelænet; hans Arme vare udstrakte og
bevægedes som en Musikanfører, der afdæmper for stærke
Strengelyde i sit stormende Orkester i Lidenskabernes altomfattende
mægtige Finale. De sidste Ord aandede han frem og dog hørligt af
Alle. Endnu en Gang havde hans Stemme eiet Stormens Tone; nu
vaklede han pludselig frem og tilbage om sin Stav. Han var synlig
træt. Bjergvinden kløftede hans hvide Skjæg og Bryn, medens hans
Øine flakkede, som om hans Kraft blev knuust af et Kølleslag fra
oven.
Borgerne bleve tause staaende. Denne Tale kom ogsaa til dem saa
underligt fraoven nedad; de norske, ranke Mænd fra den unge Stad
stode nu og saae paa de Udmærkelser, de medbragte, og følte, at de
ligesom vare af Papir. Manden var voxet fra dem.
Eneboeren vendte sig mod Colbjørnsen, hvis mandige, sørgmodige
Træk vare prægede af hans ulykkelige Hjemliv[9]. Han havde
opmærksomt lyttet til denne eensomme Sjæls Skriftemaal, der snart
rullede som en bred, frigjort Strøm, snart fremstødtes som
overhugget af Sindets Bevægelse.
»Uhrværket er ved at gaa istaa, Kvalhalmen venter mig nu derinde,«
sagde Bjørnstad. »Tilgiv en gammel Mand, — det vilde siges. Træd
indenfor. Alt, hvad jeg eier, er Eders.«
I dette Øieblik banede en besynderlig Skikkelse sig Vei mellem
Borgerne. Han var iført en lang Frakke med store Metalknapper og
et høirødt Tørklæde flagrende over et struttende Kalvekryds, medens
han svingede sin side Hat og raabte:
»Hil være Morbror Bjørnstad, Du gamle Balte! Ja, din Storhed er
gaaet over i Rygralliken paa os Allesammen. Din egen Søstersøn
Daniel, Selveier af Frederikshalds Liimkogeri og gift Ægtemand med
Liimkogerenke Reimer respekterer Dig. Jeg er stolt af Dig, Morbror
Bamse! Alle mine Sønner skal kaldes op efter Dig. Nu flytter Du ned
til mig og skal blive tilseet med Reenlighed og Proprietet; saa
kommer Bymusiken og spiller op udenfor vores Dør — hva' — sa!
Hip — hip — hurra!«
Det var Skipper Daniel, der nylig var traadt i Land fra den lille Færge
bag ved Huset. Han havde ad en Gjenvei skyndt sig herop fra
Frederikshald for at være Vidne til Familiefesten.
Ingen lagde Mærke til Liimkogeren. Alles Øine søgte Bjørnstad, hvis
graanede Skikkelse skarpt aftegnedes mod Aftenhimlen. Hans
mægtige Pande med de dybe Øine, hvorover Panden sprang frem
som en Klippe, ragede ensomt op over Menneskene, Tiden. Dette
lille Udvalg af Stadens Mænd vare i dette Øieblik et Udtryk for
Folkestemningen. Her var intet bølgende Hovedhav, ingen høilydt
Jubel med hundreder af fremstrakte Hænder, intet lokkende
Fyrværkeri, Fakkeltog, her var blot et gammelt Menneskehoved og
den store Eensomhed omkring det. Uden at Nogen vidste, hvem der
begyndte, lød pludselig den norske Nationalsang fra den lille Klynge,
høitidelig og fuldtonende i den dybe Stilhed, den eneste Hyldest, de
vidste at bringe. Bjørnstad rettede sig ved sin Krykke, det svulmede i
hans Bryst, og Taarer forsvandt i hans hvide Skjæg. Der stod den
gamle Løve endnu en Gang Ansigt til Ansigt med sit Folk, mægtig og
rank som et gammelt Fyrretræ, himmelstor for den Enkelte.
Borgerne syntes siden hen i Dagslivet, at de havde seet
Folkeaanden, nei, selve den oprindelige, herlige, lutrede og
uforgjængelige Menneskeaand. De glemte ikke det Billede siden.
Den Nat sov de Alle i fredelig Forening paa friske Høleier i Hyttens
Stue. Bjørnstad vilde hvile mellem sine Bysbørn; han laa stille hen
med Hænderne foldede over Brystet og et mildt og forklaret Udtryk.
Først henad Morgenstunden faldt han i Søvn.
Næste Dag begave Mændene fra Halden sig atter nedefter. Bagved
Huset fandtes som omtalt en primitiv Færge, der over en Sidearm af
den store Elv frembragte en Gjenvei ned i Dalen. Bjørnstad paastod
at ville ledsage sine Gjæster over Vandet til den modsatte Bred, og
man lod ham have sin Villie. Colbjørnsen og Jørgen Halvorsen ledte
ham om Bord. Da Borgerne vare satte i Land, og Colbjørnsen endnu
en Gang havde omfavnet Bjørnstad, blottede den Gamle sit Bryst,
medens Færgen skjød fra Land, og fremviste Æresborgerdiplomet;
det laa ved hans Hjerte og forlod ham ikke mere.
»Gud velsigne Jer Allesammen,« sagde Bjørnstad.
Fartøiet naaede Landgangen ved Hytten, og Jørgen sprang op paa
Stenen for at fastgjøre Prammen, hvorved den gled nogle Alen fra
Land tilbage i Strømmen. Ingen anede endnu nogen Fare; Bjørnstad
vilde med Lethed have kunnet stage sig i Land, som han saa ofte
havde gjort. Først da han lod Baadshagen falde overbord og foldede
Armene over Brystet, begyndte Jørgen at ane Uraad.
»Vær god mod Faster Ellen!« lød Bjørnstads rolige Stemme indover;
»hun er at stole paa. — Hils Olaug, mit Hjertes stolte Barn.«
Jørgen udstødte et Raab og søgte forgjæves at indhente de
gyngende Planker, der allerede førtes med den dybe, stride Strøm,
som, svulmende efter de sidste Ugers Skybrud, ilede ud mod
Sarpfossen. Hurtigere og hurtigere gled Færgen af Sted. Bjørnstad
syntes ikke at see eller høre noget mere omkring sig. Borgerne
fulgte bekymrede og grebne Fartøiet paa den modsatte,
mennesketomme Bred; de forstode, at de vare til Stede ved
Bjørnstads Ligfærd.
Allerede drønede Fossefaldet i Nærheden og sendte rygende
Skumhvirvler i Veiret ved Elvmundingen. Bjørnstads hvide Haar
flagrede i Vinden; han stirrede opad. En Gang lød et Skrig fra
Klyngen paa Land; det saae ud, som om Færgen vilde skyde ind
mellem Klipperne. Den gled forbi. Maaske vilde Bjørnstad nu kun
lande paa Evighedens Kyst. I næste Nu forsvandt han i Skum og
Fraade.
Oppe paa en fremspringende Pynt stod Faster Ellen. Hun strakte
Armene mod Himlen og udbrød:
»Store, almægtige Gud, nu forstaaer ogsaa jeg det Hele: gjennem
Braad og Brænding hjem til Dig!«

Det var atter Foraar. Bjørnstads gamle Huus, Fossegaarden, laa


nystrøget, rødmalet i den opgaaende Morgensol, skinnende under de
rødmende Fyrrestammer. Inde fra Mormors Hytte lød en kvidrende
Jubel.
»— Derfor er jeg saa glad, saa glad!« — det brød frem som et
ustandseligt Væld af unævnelig Livsfryd — »derfor er jeg saa glad,
saa glad!« — kun den ene Strofe, intet andet: »saa glad, saa glad!«
Døren blev revet op, og en slank, ung Kvindeskikkelse ilede ud, heelt
ud, yderst paa Pynten, med et nøgent, buttet, solbrændt
Drengebarn paa Armen. Hun løftede ham høit over sit Hoved, som
om hun vilde vise ham al Jordens Deilighed — nei, hun vilde vist vise
Himlen sin deilige Skat, den lille Bjørn Halvorsen.
Jørgen stod lykkestraalende ved hendes Side, en Menneskegruppe,
der i sig selv rummede det høieste og udtrykte alt.
»Hvornaar flytte vi over i det store Huus, min Olaug?« spurgte
Jørgen.
»Ikke nu, ikke endnu!« bad hans Hustru og knugede Glutten fastere
mod sin høie Barm. »Her i den gamle Hytte fødtes vor Lykke. — Kys
Mormor igjen!« udbrød hun pludselig og holdt den Lille henimod
Træstammen, hvor det store S M endnu blødte under Fyrrebarken,
fordi Sønnen bestandig holdt Saaret frisk.
Drengen slog Armene om Træet og trykkede leende Kinden derimod.
»See, Jørgen, hvor underligt!« hviskede Olaug. »Den klare Harpix
drypper endnu af de Bogstaver. Det er som levende Taarer.«
Inde i Hytten i Halvmørket skimtedes Faster Ellens karakteristiske
Ansigt. Hun støttede Hænderne om Rokkehovedet og saae
sørgmodigt paa de Unge. I Døren stod Hønen Guru og kaglede, og
søgte, rev en Fjer af sit Bryst og holdt den i Næbet op mod
Huusmoderen, da hun atter traadte over Tærskelen.
»Derfor er jeg saa glad, saa glad!« jublede Olaug og kastede sit
Drengebarn ned i Faster Ellens Skjød.
»Bøi Dig i Ydmyghed — bøi Dig i Kjærlighed!« hviskede den Gamle
og bøiede sig selv over Drengen.
Men den lille Bjørn strakte sine smaa knyttede Hænder opad og lo
himmelhøit mod Himlen.
Mangen en stille Aften lød Vuggevisens Toner oppe fra Fjeldpynten
ud over Dalen, bævende og manende, en Takkehilsen til det store og
Svundne, tillige en forjættende Forsikring om, at dets rige
Følelsesvæld brusende brød sig i Fossefald gjennem Nuet, for
velsignelsesrigt at strømme over i Fremtidens Skjød.
De Toner lyde endnu, ville altid lyde.

Ende.
INDHOLDSFORTEGNELSE.
Side
»S. M.« 1
Hölandsslaget 21
En Norges Søn 47
Før Stormen 65
Fra Bjørnehien 77
Brændetyven 95
Hjemmets Fugl 111
Store Torsken! 127
Visen 143
Spionen 163
Et falsk Signal 183
Klokkeren fra Id 199
Ole Svendsens Død 215
Colbjørnsens »brogede Karle«
235
Stormuglen 253
Skjændselsbarnet 271
Ildskriften læses endnu paa
Krønikens evige Tavle 291
Det brænder, han render —
Ritsch! 309
Mari Bjørnstad 335
I Løbegraven 347
Den store Fred 369
FODNOTER.
[1] En Klove er en liden Sænkning mellem to Bjerge.
[2] Præsten, Hr. Peder Rumohr, der havde tjent som Cornet under
Hertugen af Würtemberg mod Jacob Stuart, gjorde sig velfortjent
under Kong Carls Indfald i Norge, idet han listelig forledede
General Aschenberg ved falske Rygter til at trække sig tilbage
over Grændsen og saaledes væsentlig bidrog til, at
Nordmændene sloge det svenske Parti paa Mors, hvor bl. a. Kong
Carls Krigskasse fandtes, og hvor Fjenden mistede 300 Mand. Da
Kong Carl med uforrettet Sag drog sig tilbage fra Christiania, lod
han Præsten overrumple og slæbe med i Fangenskab til Sverig,
hvor han efter to Aars Lidelser døde af Skjørbug og Vattersot,
»saasom han meest spiste Drøvelsens Brød.« Efter sit Ønske fik
han til Begravelsestext Job 3. v. 18: »Der have Fangerne Frihed
tillige; de høre ikke Trængerens Røst.«
[3] Carl den Tolvte kunde endnu, hærdet ved Legemsøvelser og
Faste, iført Rytterstøvler, lægge sin Fod bag Øret, paa Hesteryg.
[4] Carolinere kaldtes de faa graanede og hærdede Krigere, der
havde overlevet Carl den Tolvte og hans Krigstogt.
[5] Forfatterens Svigermoder var en høitbegavet Dame, Søster til
den bekjendte norske Maler, August Cappelen, hvis Malerier
findes i Christiania Nationalgalleri.
[6] Dr. C. Palludan-Müller er i sine udmærkede, skarpsindige,
kritisk-historiske Undersøgelser kommen til det Resultat, at Kong
Carl efter al Sandsynlighed maa være faldet for et Projectil fra
Fæstningen.
[7] Det er et karakteristisk Kjendetegn for det stærke Indtryk,
som denne tragiske Begivenhed gjorde paa Øienvidnerne, at flere
af disse og blandt dem Siquier i Vildelse senere hen beskyldte sig
selv for at have myrdet Kongen, hvilke Tilstaaelser dog klart er
beviist kun skyldes Hallucinationer. De senere militaire og
sagkyndige Undersøgelser, der fandt Sted paa selve
Gjerningsstedet saavelsom paa Liget, have tilstrækkelig klargjort,
at ikke Skygge af Mistanke om en slig Niddingsdaad, som dette
Kongemord vilde være, klæber ved den tapre og hæderlige
svenske Nation.
[8] Denne Orden har existeret i Frederikshald, traadte dog først
ud i Livet 1ste Januar 1750. Ordenstegnet var da en Triangel,
hvilken var forfærdiget af Guld, som det ædleste og reneste af
Metallerne, for at tjene dem, som dermed beæredes, til en
bestandig Paamindelse »altid at kultivere de ædle og uforfalskede
Dyder, hvormed den er erhvervet«. Paa den ene Side er graveret
disse Ord: »l'ordre de la constance, institué par les dames à
Frederikshald le 9me Decbr 1749.« Paa den anden Side staaer
disse Ord: »Dedié au vrai mérite en dépit des franc Maçons.« Den
bæres udi et blaat, vatret Baand Couleur d'azur og bindes med en
dobbelt Sløife i det tredie Knaphul af Vesten. Den første Mand,
der udmærkedes med denne Orden, var Rudolph de Romeling,
Kgl. Mayst. bestalte Major.
[9] Colbjørnsens Hustru var drikfældig og letfærdig.
Afskriverens rettelser
s. 4: rødere, hendes Blik[Bllk] fik et spændt Udtryk.
Morgenvinden
s. 9: Hun vil ikke tage det ilde op, naar hun hører, vi[v]
s. 11: hendes Ansigt [i] Bukler og Krøller, over hvilke en
saakaldet Fontange
s. 34: at vi ikke fik hende grundig forhørt[førhørt]. — Skal vi
gjøre
s. 50: sløv og følelsesløs[følesløs]? — Javist, Hustru!« udbrød
Bjørnstad
s. 52: Hver Nordmand[Normand], som vil norsk
Retfærdighed fuldt ud
s. 52: Som Bjørnstad stod dèr[dér] i blodfuld Kraft, mens
s. 72: »Kan Skipper Daniel[Daniels], der er en saa forfaren
Mand,
s. 73: »Ja, svar paa det, Daniel[Daniels],« raabte en mager
s. 73: Deres beredvillige Tjener bevise, at det, Skipper
Daniel[Daniels]
s. 74: Skipper Daniel[Daniels] slog en Latter op, der
skingrende
s. 91: som[sam] ham dèr« — han nikkede over mod
s. 91: som ham dèr[dér]« — han nikkede over mod
s. 98: Aschenberg[Asheberg] ved Herrebroen havde maattet
lade sine Folk
s. 99: reiste sig paa Thinge og sagde til svenske
Kong[Konge] Oluf:
s. 106: Syne i Huulveien; deres Karabiner lyste i
Maaneskinnet[Maaneskinnnet],
s. 119: Lidt efter skjød Jørgen sit Arbeide[Arbejde] fra sig og
s. 124: Hvad Ret havde han vel til [at] beklage sig? Han
s. 138: mod Bjørnstads[Bjønstads] Gaard.
s. 159: hviskede Månsson; »det er Dødsdeliriet[Dødsdellriet],
som kriller i
s. 184: Carl[Karl] den Tolvte forsmaaede Tidens
Allongeparyk.
s. 208: »Alt er i Orden, Hr. Stadskapitain[Stadskaptain],«
meldte
s. 222: Jeres[jeres] Folk. Skipper Daniel var her i Møllen for
en
s. 229: Skoven og indjog Folkene den Tanke, at de bleve
forfulgte[for fulgte]
s. 247: »Du tilraaber dem »Holdt! — hvem dèr[dér]?« og
naar
s. 252: hvor Musketild og Kanontorden[Kanontordenen]
ledsagede
s. 257: Aar havde bragt frelst i Land, og Brovagten i
Frederikshald[Frederederikshald]
s. 261: der saa lyst anden Gang for Bager Hans
Høyer[Hoyer] og
s. 269: Gevær blev afskudt[sfskudt]. Thi da de vare komne
Fjenden
s. 276: Paa Hjørnet af Kirke- og
Borgerskandsegade[Borgerskandsgade] laa
s. 278: »Enkemadam Anea Høyer[Höyer], alene! Kommer
ikke
s. 280: og raadslaa[raaslaa] med hverandre om at stikke vor
By i
s. 280: det at have Hjerte i Brystet at ville stege sine[sin]
Medskabninger
s. 300: som vi forlode i Ulle Halvorsens Kviststue i
Walcks[Walkers]
s. 303: Tvangsægteskabet, Lysningen i Luneland[Lumeland].
Han blev
s. 307: »Jeg er kun en[et] af Norges ringeste Døtre,«
hviskede
s. 316: hjem langveis[langsveis] fra. »Ilden skal slukkes.
Dirigeer
s. 317: sig i Walcks[Walkers] Gaard, gik Spisesalsdørene op
til Maiestætens
s. 336: holde Øie med Nordmændene[Normændene] og
svække deres Modstandskraft
s. 350: syntes saaledes at have været[være] forgjæves og
deres By
s. 353: mod det Sted, hvor Arbeidet[Arbejdet] med de nye
Linier skulde
s. 362: var dræbt af en ubekjendt[uebkjendt] Haand.«
s. 363: Fødder. General Schwerin havde stillet[sfillet] Vagt i
Løbegraven,
s. 363: Da dette var varetaget, vendte Siquier[Sequier] sig til
s. 365: intet undtagen Gustav Adolphs[Adolps] Portrait og
Bønnebog.
s. 374: den skyder sig frem, beriget ved utallige
Vandaarer[Vaandaarer]
s. 374: Midt i al denne Travlhed fløi Faster[Fasters] Ellens Blik
s. 385: disse Ord: »Dedié au vrai mérite[mêrite] en dépit des
franc Maçons.«
s. 392: der afdæmper for stærke Strengelyde[Strengelyd] i
sit stormende
s. 392: blev knuust af et Kølleslag fra oven[fraoven].
*** END OF THE PROJECT GUTENBERG EBOOK BJØRNEÆT:
NATIONALHISTORISK ROMAN ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like