100% found this document useful (2 votes)
88 views55 pages

PHP and MySQL For Dynamic Web Sites Fifth Edition Ullman Instant Download

The document provides information about the book 'PHP and MySQL for Dynamic Web Sites, Fifth Edition' by Larry Ullman, which covers the essentials of creating dynamic, database-driven websites using PHP and MySQL. It includes a detailed table of contents outlining various topics such as PHP syntax, MySQL introduction, web application development, and security methods. Additionally, it offers links to other related resources and books on PHP and MySQL.

Uploaded by

rmupixw799
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)
88 views55 pages

PHP and MySQL For Dynamic Web Sites Fifth Edition Ullman Instant Download

The document provides information about the book 'PHP and MySQL for Dynamic Web Sites, Fifth Edition' by Larry Ullman, which covers the essentials of creating dynamic, database-driven websites using PHP and MySQL. It includes a detailed table of contents outlining various topics such as PHP syntax, MySQL introduction, web application development, and security methods. Additionally, it offers links to other related resources and books on PHP and MySQL.

Uploaded by

rmupixw799
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/ 55

PHP and MySQL for Dynamic Web Sites Fifth

Edition Ullman download

https://textbookfull.com/product/php-and-mysql-for-dynamic-web-
sites-fifth-edition-ullman/

Download full version ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

PHP for the Web Visual QuickStart Guide 5th Edition


Larry Ullman

https://textbookfull.com/product/php-for-the-web-visual-
quickstart-guide-5th-edition-larry-ullman/

PHP and MySQL Web Development 5th Edition Developer s


Library Luke Welling

https://textbookfull.com/product/php-and-mysql-web-
development-5th-edition-developer-s-library-luke-welling/

Learning PHP, MySQL & JavaScript, 6th Edition Robin


Nixon

https://textbookfull.com/product/learning-php-mysql-
javascript-6th-edition-robin-nixon/

A Web Based Introduction to Programming Essential


Algorithms Syntax and Control Structures Using Php Html
and Mariadb MySQL Mike O’Kane

https://textbookfull.com/product/a-web-based-introduction-to-
programming-essential-algorithms-syntax-and-control-structures-
using-php-html-and-mariadb-mysql-mike-okane/
Learning PHP MySQL JavaScript Early Release 6th Edition
Robin Nixon

https://textbookfull.com/product/learning-php-mysql-javascript-
early-release-6th-edition-robin-nixon/

PHP Web Services APIs for the Modern Web 2nd Edition
Lorna Jane Mitchell

https://textbookfull.com/product/php-web-services-apis-for-the-
modern-web-2nd-edition-lorna-jane-mitchell/

Beginning PHP and MySQL: From Novice to Professional


5th Edition Frank M. Kromann

https://textbookfull.com/product/beginning-php-and-mysql-from-
novice-to-professional-5th-edition-frank-m-kromann/

Learn PHP 8: Using MySQL, JavaScript, CSS3, and HTML5


Second Edition Steve Prettyman

https://textbookfull.com/product/learn-php-8-using-mysql-
javascript-css3-and-html5-second-edition-steve-prettyman/

Learning PHP MySQL JavaScript With jQuery CSS HTML5 5th


Edition Robin Nixon

https://textbookfull.com/product/learning-php-mysql-javascript-
with-jquery-css-html5-5th-edition-robin-nixon/
Visual Quickpro Guide

PHP and MySQL for Dynamic


Web Sites
Fifth Edition

Larry Ullman
Visual QuickPro Guide
PHP and MySQL for Dynamic Web Sites, Fifth Edition
Larry Ullman
Peachpit Press
www.peachpit.com
Copyright © 2018 by Larry Ullman
To report errors, please send a note to: errata@peachpit.com
Peachpit Press is a division of Pearson Education.
Editor: Mark Taber
Copy Editor: Elizabeth Welch
Technical Reviewer: Timothy Boronczyk
Production Coordinator: David Van Ness
Compositor: Danielle Foster
Proofreader: Scout Festa
Indexer: Valerie Haynes Perry
Cover Design: RHDG / Riezebos Holzbaur Design Group, Peachpit
Press
Interior Design: Peachpit Press
Logo Design: MINE™ www.minesf.com
Notice of Rights
This publication is protected by copyright, and permission should be
obtained from the publisher prior to any prohibited reproduction,
storage in a retrieval system, or transmission in any form or by any
means, electronic, mechanical, photocopying, recording, or
otherwise. For information on obtaining permission for reprints and
excerpts, please complete the form at
http://www.pearsoned.com/permissions/
Notice of Liability
The information in this book is distributed on an “As Is” basis,
without warranty. While every precaution has been taken in the
preparation of the book, neither the author nor Peachpit Press shall
have any liability to any person or entity with respect to any loss or
damage caused or alleged to be caused directly or indirectly by the
instructions contained in this book or by the computer software and
hardware products described in it.
Trademarks
Visual QuickPro Guide is a registered trademark of Peachpit Press, a
division of Pearson Education. MySQL is a registered trademark of
MySQL AB in the United States and in other countries. Macintosh
and macOS are registered trademarks of Apple, Inc. Microsoft and
Windows are registered trademarks of Microsoft Corp. Other product
names used in this book may be trademarks of their own respective
owners. Images of Web sites in this book are copyrighted by the
original holders and are used with their kind permission. This book is
not officially endorsed by nor affiliated with any of the above
companies, including MySQL AB.
Unless otherwise indicated herein, any third party trademarks that
may appear in this work are the property of their respective owners
and any references to third party trademarks, logos or other trade
dress are for demonstrative or descriptive purposes only. Such
references are not intended to imply any sponsorship, endorsement,
authorization, or promotion of Peachpit Press products by the
owners of such marks, or any relationship between the owner and
Peachpit Press or its affiliates, authors, licensees or distributors.
ISBN-13: 978-0-13-430184-6
ISBN-10: 0-13-430184-6
1 17
Printed and bound in the United States of America
Dedication
Dedicated to the fine faculty at my alma mater, Northeast Missouri
State University. In particular, I would like to thank Dr. Monica
Barron, Dr. Dennis Leavens, Dr. Ed Tyler, and Dr. Cole Woodcox,
whom I also have the pleasure of calling my friend. I would not be
who I am as a writer, as a student, as a teacher, or as a person if it
were not for the magnanimous, affecting, and brilliant instruction I
received from these educators.

Special Thanks to:


My heartfelt thanks to everyone at Peachpit Press, as always.
My gratitude to the fine editor on this project, Mark Taber, for
leading the way and putting up with too many delayed emails and
chapters!
Thanks to David Van Ness and Elizabeth Welch for their hard work,
helpful suggestions, and impressive attention to detail. Thanks to
Scout Festa for ensuring the writing is “pixel perfect.” Thanks also to
Valerie Perry for indexing and Danielle Foster for laying out the book,
and thanks to Timothy Boronczyk for his technical review.
Kudos to the good people working on PHP, MySQL, Apache,
phpMyAdmin, MAMP, and XAMPP, among other great projects. And a
hearty “cheers” to the denizens of the various newsgroups, mailing
lists, support forums, etc., who offer assistance and advice to those
in need.
Thanks, as always, to the readers, whose support gives my job
relevance. An extra helping of thanks to those who provided the
translations in Chapter 17, “Example—Message Board,” and who
offered up recommendations as to what they’d like to see in this
edition.
Finally, I would not be able to get through a single book if it weren’t
for the love and support of my wife, Jessica. And a special shout-out
to Zoe and Sam, who give me reasons to, and not to, write books!.
Table of Contents
Introduction

Chapter 1 Introduction to PHP


Basic Syntax
Sending Data to the Browser
Writing Comments
What Are Variables?
Introducing Strings
Concatenating Strings
Introducing Numbers
Introducing Constants
Single vs. Double Quotation Marks
Basic Debugging Steps
Review and Pursue

Chapter 2 Programming with PHP


Creating an HTML Form
Handling an HTML Form
Conditionals and Operators
Validating Form Data
Introducing Arrays
For and While Loops
Review and Pursue

Chapter 3 Creating Dynamic Web Sites


Including Multiple Files
Handling HTML Forms, Revisited
Making Sticky Forms
Creating Your Own Functions
Review and Pursue
Chapter 4 Introduction to MySQL
Naming Database Elements
Choosing Your Column Types
Choosing Other Column Properties
Accessing MySQL
Review and Pursue

Chapter 5 Introduction to SQL


Creating Databases and Tables
Inserting Records
Selecting Data
Using Conditionals
Using LIKE and NOT LIKE
Sorting Query Results
Limiting Query Results
Updating Data
Deleting Data
Using Functions
Review and Pursue

Chapter 6 Database Design


Normalization
Creating Indexes
Using Different Table Types
Languages and MySQL
Time Zones and MySQL
Foreign Key Constraints
Review and Pursue

Chapter 7 Advanced SQL and MySQL


Performing Joins
Grouping Selected Results
Advanced Selections
Performing FULLTEXT Searches
Optimizing Queries
Performing Transactions
Database Encryption
Review and Pursue

Chapter 8 Error Handling and Debugging


Error Types and Basic Debugging
Displaying PHP Errors
Adjusting Error Reporting in PHP
Creating Custom Error Handlers
PHP Debugging Techniques
SQL and MySQL Debugging Techniques
Review and Pursue

Chapter 9 Using PHP with MySQL


Modifying the Template
Connecting to MySQL
Executing Simple Queries
Retrieving Query Results
Ensuring Secure SQL
Counting Returned Records
Updating Records with PHP
Review and Pursue

Chapter 10 Common Programming Techniques


Sending Values to a Script
Using Hidden Form Inputs
Editing Existing Records
Paginating Query Results
Making Sortable Displays
Review and Pursue
Chapter 11 Web Application Development
Sending Email
Handling File Uploads
PHP and JavaScript
Understanding HTTP Headers
Date and Time Functions
Performing Transactions
Review and Pursue

Chapter 12 Cookies and Sessions


Making a Login Page
Making the Login Functions
Using Cookies
Using Sessions
Improving Session Security
Review and Pursue

Chapter 13 Security Methods


Preventing Spam
Validating Data by Type
Validating Files by Type
Preventing XSS Attacks
Using the Filter Extension
Preventing SQL Injection Attacks
Securing Passwords with PHP
Review and Pursue

Chapter 14 Perl-Compatible Regular Expressions


Creating a Test Script
Defining Simple Patterns
Using Quantifiers
Using Character Classes
Finding All Matches
Using Modifiers
Matching and Replacing Patterns
Review and Pursue

Chapter 15 Introducing jQuery


What Is jQuery?
Incorporating jQuery
Using jQuery
Selecting Page Elements
Event Handling
DOM Manipulation
Using Ajax
Review and Pursue

Chapter 16 An OOP Primer


Fundamentals and Syntax
Working with MySQL
The DateTime Class
Review and Pursue

Chapter 17 Example—Message Board


Making the Database
Writing the Templates
Creating the Index Page
Creating the Forum Page
Creating the Thread Page
Posting Messages
Review and Pursue

Chapter 18 Example—User Registration


Creating the Templates
Writing the Configuration Scripts
Creating the Home Page
Registration
Activating an Account
Logging In and Logging Out
Password Management
Review and Pursue

Appendix A Installation
Installation on Windows
Installation on macOS
Managing MySQL Users
Testing Your Installation
Configuring PHP
Configuring Apache

Index
Introduction
Today’s web users expect exciting pages that are updated frequently
and provide a customized experience. For them, web sites are more
like communities, to which they’ll return time and again. At the same
time, site administrators want pages that are easier to update and
maintain, understanding that’s the only reasonable way to keep up
with visitors’ expectations. For these reasons and more, PHP and
MySQL have become the de facto standards for creating dynamic,
database-driven web sites.
This book represents the culmination of my many years of web
development experience coupled with the value of having written
several previous books on the technologies discussed herein. The
focus of this book is on covering the most important knowledge in
the most efficient manner. It will teach you how to begin developing
dynamic web sites and give you plenty of example code to get you
started. All you need to provide is an eagerness to learn.
Well, that and a computer.

What Are Dynamic Web Sites?


Dynamic web sites are flexible and potent creatures, more accurately
described as applications than merely sites. Dynamic web sites
Respond to different parameters (for example, the time of day or
the version of the visitor’s browser)
Have a “memory,” allowing for user registration and login, e-
commerce, and similar processes
Almost always integrate HTML forms, allowing visitors to perform
searches, provide feedback, and so forth
Often have interfaces where administrators can manage the
content
Are easier to maintain, upgrade, and build upon than statically
made sites
Many technologies are available for creating dynamic web sites. The
most common are ASP.NET (Active Server Pages, a Microsoft
construct), JSP (JavaServer Pages), ColdFusion, Ruby on Rails (a
web development framework for the Ruby programming language),
and PHP. Dynamic sites don’t always rely on a database, but more
and more of them do, particularly as excellent database applications
like MySQL and MongoDB are available at little to no cost.
What Happened to PHP 6?
When I wrote a previous edition of this book, PHP 6 and
MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide,
the next major release of PHP—PHP 6—was
approximately 50 percent complete. Thinking that PHP 6
would therefore be released sometime after the book was
published, I relied on a beta version of PHP 6 for a bit of
that edition’s material. And then… PHP 6 died.
One of the key features planned for PHP 6 was support
for Unicode, meaning that PHP 6 would be able to work
natively with any language. This would be a great
addition to an already popular programming tool.
Unfortunately, implementing Unicode support went from
being complicated to quite difficult, and the developers
behind the language tabled development of PHP 6. Not all
was lost, however; some of the other features planned for
PHP 6, such as support for namespaces (an object-
oriented programming concept), were added to PHP 5.3.
When it was time to release the next major version of
PHP, it was decided to name it PHP 7 to avoid confusion
with the PHP 6 version that was started but never
completed.

What is PHP?
PHP originally stood for “Personal Home Page” when it was created
in 1994 by Rasmus Lerdorf to track the visitors to his online résumé.
As its usefulness and capabilities grew (and as it started being used
in more professional situations), it came to mean “PHP: Hypertext
Preprocessor.”
According to the official PHP web site, found at www.php.net ,
PHP is a “popular general-purpose scripting language that is
especially suited to web development.” It’s a long but descriptive
definition, whose meaning I’ll explain.
The home page for PHP.
Starting at the end of that statement, to say that PHP is especially
suited to web development means that although you can use PHP
for non-web development purposes, it’s best suited for that. The
corollary is that although many other technologies can be used for
web development, that may not be what they’re best suited for.
Simply put, if you’re hoping to do web development, PHP is an
excellent choice.
Also, PHP is a scripting language, as opposed to a compiled
language: PHP was designed to write web scripts, not stand-alone
applications (although, with some extra effort, you can create
applications in PHP). PHP scripts run only after an event occurs—for
example, when a user submits a form or goes to a URL (uniform
resource locator, the technical term for a web site address).
I should add to this definition that PHP is a server-side, cross-
platform technology, both descriptions being important. Server-side
refers to the fact that everything PHP does occurs on the server. A
web server application, like Apache or Microsoft’s IIS (Internet
Information Services), is required and all PHP scripts must be
accessed through a URL (http://something). Its cross-platform
nature means that PHP runs on most operating systems, including
Windows, Unix (and its many variants), and Macintosh. More
important, the PHP scripts written on one server will normally work
on another with little or no modification.
At the time this book was written, PHP was at version 7.1.7.
Although PHP 7 is a major release, the most important changes are
in its core, with PHP 7 being significantly more performant than PHP
5.
For the most part, the examples in this book will work fine so long as
you’re using at least version 5.4. Some functions and features
covered will require more specific or current versions, like PHP 5.6 or
greater. In those cases, I will make it clear when the functionality
was added to PHP, and provide alternative solutions if you have a
slightly older version of the language.
More information about PHP can always be found at PHP.net.

Why use PHP?


Put simply, when it comes to developing dynamic web sites, PHP is
better, faster, and easier to learn than the alternatives. What you get
with PHP is excellent performance, a tight integration with nearly
every database available, stability, portability, and a nearly limitless
feature set due to its extendibility. All of this comes at no cost (PHP
is open source) and with a very manageable learning curve. PHP is
one of the best marriages I’ve ever seen between the ease with
which beginning programmers can start using it and the ability for
more advanced programmers to do everything they require.
Finally, the proof is in the pudding: PHP has seen an exponential
growth in use since its inception, and is the server-side technology
of choice on over 82 percent of all web sites . In terms of all
programming languages, PHP is the sixth most popular .
The Web Technology Surveys site provides this graphic regarding
server-side technologies
(www.w3techs.com/technologies/overview/programming_
language/all).

The Tiobe Index (https://www.tiobe.com/tiobe-index/)


uses a combination of factors to rank the popularity of programming
languages.
Of course, you might assume that I, as the author of a book on PHP
(several, actually), have a biased opinion. Although not nearly to the
same extent as I have with PHP, I’ve also developed sites using
JavaServer Pages (JSP), Ruby on Rails (RoR), Sinatra (another Ruby
web framework), and ASP.NET. Each has its pluses and minuses, but
PHP is the technology I always return to. You might hear that it
doesn’t perform or scale as well as other technologies, but Yahoo,
Wikipedia, and Facebook all use PHP, and you can’t find many sites
more visited or demanding than those.
You might have heard that PHP is less secure. But security isn’t in
the language; it’s in how that language is used. Rest assured that a
complete and up-to-date discussion of all the relevant security
concerns is provided by this book.

How PHP works


As previously stated, PHP is a server-side language. This means that
the code you write in PHP sits on a host computer called a server.
The server sends web pages to the requesting visitors (you, the
client, with your browser).
When a visitor goes to a site written in PHP, the server reads the
PHP code and then processes it according to its scripted directions.
In the example shown in , the PHP code tells the server to send
the appropriate data—HTML code—to the browser, which treats the
received code as it would a standard HTML page.

How PHP fits into the client/server model when a user requests a
page.
This differs from a static HTML site where, when a request is made,
the server merely sends the HTML data to the browser and there is
no server-side interpretation occurring . Because no server-side
action is required, you can run HTML pages in your browser without
using a server at all.
The client/server process when a request for a static HTML page
is made.
To the end user and the browser there is no perceptible difference
between what home.html and home.php may look like, but how
that page’s content was created will be significantly different.

What is MySQL?
MySQL (www.mysql.com) is the world’s most popular open
source database. In fact, today MySQL is a viable competitor to
pricey goliaths such as Oracle and Microsoft’s SQL Server (and,
ironically, MySQL is owned by Oracle). Like PHP, MySQL offers
excellent performance, portability, and reliability, with a moderate
learning curve and little to no cost.
The home page for the MySQL database application.
MySQL is a database management system (DBMS) for relational
databases (therefore, MySQL is an RDBMS). A database, in the
simplest terms, is a collection of data, be it text, numbers, or binary
files, stored and kept organized by the DBMS.
There are many types of databases, from the simple flat-file to
relational to object-oriented to NoSQL. A relational database uses
multiple tables to store information in its most discernible parts.
Although relational databases may involve more thought in the
design and programming stages, they offer improved reliability and
data integrity that more than make up for the extra effort required.
Further, relational databases are more searchable and allow for
concurrent users.
By incorporating a database into a web application, some of the data
generated by PHP can be retrieved from MySQL . This further
moves the site’s content from a static (hard-coded) basis to a
flexible one, flexibility being the key to a dynamic web site.
How most of the dynamic applications in this book will work,
using both PHP and MySQL.
MySQL is an open source application, like PHP, meaning that it is
free to use or even modify (the source code itself is downloadable).
There are occasions when you should pay for a MySQL license,
especially if you are making money from the sales or incorporation
of the MySQL product. Check MySQL’s licensing policy for more
information on this.
The MySQL software consists of several pieces, including the MySQL
server (mysqld, which runs and manages the databases), the MySQL
client (mysql, which gives you an interface to the server), and
numerous utilities for maintenance and other purposes. PHP has
always had good support for MySQL, and that is even truer in the
most recent versions of the language.
MySQL has been known to handle databases as large as 60,000
tables with more than several billion rows. MySQL can work with
tables as large as thousands of terabytes on some operating
systems, generally a healthy 4 GB otherwise. MySQL is used by
NASA and the U.S. Census Bureau, among many others.
As of this writing, MySQL is on version 5.7.18. The version of MySQL
you have affects what features you can use, so it’s important that
you know what you’re working with. For this book, MySQL 5.7.14
was used, although you should be able to do everything in this book
as long as you’re using a version of MySQL greater than 5.0.
Pronunciation Guide
Trivial as it may be, I should clarify up front that MySQL is
technically pronounced “My Ess Cue Ell,” just as SQL
should be said “Ess Cue Ell.” This is a question many
people have when first working with these technologies.
Though not a critical issue, it’s always best to pronounce
acronyms correctly.

What You’ll Need


To follow the examples in this book, you’ll need the following tools:
A web server application (for example, Apache, Nginx, or IIS)
PHP
MySQL
A browser (Microsoft’s Internet Explorer or Edge, Mozilla’s
Firefox, Apple’s Safari, Google’s Chrome, etc.)
A text editor, PHP-capable WYSIWYG application (Adobe’s
Dreamweaver qualifies), or IDE (integrated development
environment)
An FTP application, if using a remote server
One of the great things about developing dynamic web sites with
PHP and MySQL is that all of the requirements can be met at no cost
whatsoever, regardless of your operating system! Apache, PHP, and
MySQL are each free, browsers can be had without cost, and many
good text editors are available for nothing.
The appendix discusses the installation process on the Windows and
macOS operating systems. If you have a computer, you are only a
couple of downloads away from being able to create dynamic web
sites (in that case, your computer would represent both the client
and the server in and ). Conversely, you could purchase web
hosting for only dollars per month that will provide you with a PHP-
and MySQL-enabled environment already online.
About This Book
This book teaches you how to develop dynamic web sites with PHP
and MySQL, covering the knowledge that most developers might
require. In keeping with the format of the Visual QuickPro series, the
information is discussed using a step-by-step approach with
corresponding images. The focus has been kept on real-world,
practical examples, avoiding “here’s something you could do but
never would” scenarios. As a practicing web developer myself, I
wrote about the information that I use and avoided those topics
immaterial to the task at hand. As a practicing writer, I made certain
to include topics and techniques that I know readers are asking
about.
The structure of the book is linear, and the intention is that you’ll
read it in order. It begins with three chapters covering the
fundamentals of PHP (by the second chapter, you will have already
developed your first dynamic web page). After that, there are four
chapters on SQL (Structured Query Language, which is used to
interact with all databases) and MySQL. Those chapters teach the
basics of SQL, database design, and the MySQL application in
particular. Then there’s one chapter on debugging and error
management, information everyone needs. This is followed by a
chapter introducing how to use PHP and MySQL together, a
remarkably easy thing to do.
The following five chapters teach more application techniques to
round out your knowledge. Security, in particular, is repeatedly
addressed in those pages. The next two chapters expand your
newfound knowledge into subjects that, though not critical, are ones
you’ll want to pick up in time regardless. Finally, I’ve included two
example chapters, in which the heart of different web applications
are developed, with instructions.
Is this book for you?
This book was written for a wide range of people within the
beginner-to-intermediate range. The book makes use of HTML5, so
solid experience with HTML is a must. Although this book covers
many things, it does not formally teach HTML or web design. Some
CSS is sprinkled about these pages but also not taught.
Second, this book expects that you have one of the following:
The drive and ability to learn without much hand holding, or…
Familiarity with another programming language (even solid
JavaScript skills would qualify), or…
A cursory knowledge of PHP
Make no mistake: This book covers PHP and MySQL from A to Z,
teaching everything you’ll need to know to develop real-world web
sites, but the early chapters in particular cover PHP at a quick pace.
For this reason I recommend either some programming experience
or a curious and independent spirit when it comes to learning new
things. If you find that the material goes too quickly, you should
probably start off with the latest edition of my book PHP for the
World Wide Web: Visual QuickStart Guide, which goes at a much
more tempered pace.
No database experience is required, since SQL and MySQL are
discussed starting at a more basic level.

What’s new in this edition


The first four editions of this book have been very popular, and I’ve
received a lot of positive feedback on them (thanks!). In writing this
new edition, I focused on ensuring the material is accurate, up to
date, and in keeping with today’s standards and best practices. The
changes in this edition include
Updating all the code to use HTML5
Use of more modern HTML design techniques, including multiple
examples of the Twitter Bootstrap framework
Updating everything for the latest versions of PHP and MySQL
Additional PHP and MySQL examples, such as performing
transactions from a PHP script
Even more information and examples for improving the security
of your scripts and sites
Removal of outdated content (e.g., things used in older versions
of PHP or no longer applicable)
Return of the installation appendix to the printed book (in the
fourth edition, the appendix was freely available online instead)
For those of you that also own a previous edition (thanks, thanks,
thanks!), I hope you find this to be a fresh and sharp update to an
already excellent resource.

How this book compares to my other books


This is my fourth PHP and/or MySQL title, after (in order)
PHP for the World Wide Web: Visual QuickStart Guide
PHP Advanced and Object-Oriented Programming: Visual
QuickPro Guide
MySQL: Visual QuickStart Guide
I hope this résumé implies a certain level of qualification to write this
book, but how do you, as a reader standing in a bookstore, decide
which title is for you? Of course, you are more than welcome to
splurge and buy the whole set, earning my eternal gratitude, but…
The PHP for the World Wide Web: Visual QuickStart Guide book is
very much a beginner’s guide to PHP. This title overlaps it some,
mostly in the first three chapters, but uses new examples so as not
to be redundant. For novices, this book acts as a follow-up to that
one. The advanced book is really a sequel to this one, as it assumes
a fair amount of knowledge and builds on many things taught here.
The MySQL book focuses almost exclusively on MySQL (there are but
two chapters that use PHP).
With that in mind, read the section “Is this book for you?” and see if
the requirements apply. If you have no programming experience at
all and would prefer to be taught PHP more gingerly, my first book
Exploring the Variety of Random
Documents with Different Content
pushed before the French evacuated Burgos. Bessières, therefore,
had much to say in favour of his view, that the point of danger was
in the Ebro valley and not in Biscay. King Joseph, convinced by his
arguments, left Ney unreinforced, and took post with the 6,000 men
of the central reserve at Vittoria. His conclusion that Bilbao was not
the true objective of the Spaniards was soon confirmed by other
movements of the enemy. The feeble columns of Castaños were at
last showing on the Central Ebro, and Palafox was on the move on
the side of Aragon.
Under the idea that all Blake’s Biscayan expedition had been no
more than a feint and a diversion, and that the real blow would be
struck on the Ebro, Jourdan and the King now directed Ney to come
back from Bilbao and to take up his old positions. The Marshal
obeyed: leaving General Merlin with 3,000 men in the Biscayan
capital, he returned with 7,000 bayonets to La Guardia, on the
borders of Alava and Navarre. His old head quarters at Logroño,
beyond the Ebro, had been occupied by the head of one of
Castaños’s columns. He did not attack this force, but merely
encamped opposite it, on the northern bank of the river [October 5]
[399]
.
Part of Northern Spain.

It is now time to review the position and forces of the Spanish


armies, which were at last up in the fighting line. Blake’s 32,000
Asturians[400] and Galicians were divided into two masses, at
Valmaceda and Villarcayo, on the two sides of the Cantabrian hills.
They were within three marches of each other, and the whole could
be turned either against Biscay or against Vittoria, as the opportunity
might demand. But between Blake and the central divisions of the
Spanish army there was a vast gap. This, at a later period of the
campaign, was filled up by bringing forward the 12,000 men of the
Estremaduran army to Burgos: but this force, insufficient as it was
for the purpose, had not reached the front: in the middle of October
it had not even arrived at Madrid[401]. There seems to have been at
Burgos nothing more than a detached battalion or two, which had
occupied the place when Bessières drew back towards the Ebro[402].
Of all the Spanish forces, the nearest organized corps on Blake’s
right consisted of the main body of this same army of Castile. This
division, for it was no more, consisted of about 10,000 or 11,000
men: it contained a few regular corps (Regiment of Cantabria, a
battalion of Grenadiers, the Leon Militia) which had been lent to it by
the army of Andalusia, and twelve raw Leonese and Castilian
battalions, of the new levy which Cuesta had raised. There were also
some 800 cavalry with it. The commander was now Pignatelli, for
Eguia (who had originally been told off to the post) had fallen sick.
This small and inefficient force was at Logroño on the Central Ebro,
having taken possession of that place when it was evacuated by
Marshal Ney in the last week of September. A little further down the
river lay the 2nd Division of the army of Andalusia, which, under the
orders of Coupigny, had taken a creditable part in the battle of
Baylen. Released by the Junta of Seville in September, it had at last
gone forward and joined Castaños. But it was somewhat changed in
composition, for three of its original fourteen battalions had been
withdrawn[403] and sent to Catalonia, while three new Andalusian
corps had replaced them. Its commander was now General
Grimarest, Coupigny having been told off to another sphere of duty.
The division numbered about 6,000 bayonets, with 400 or 500
cavalry, and a single battery. It occupied Lodosa, on the north bank
of the Ebro, some twelve miles down-stream from Logroño. Quite
close to its right there lay at Calahorra the 4th Division of the army
of Andalusia, under La Peña—a somewhat stronger force—about
7,500 foot, with 400 horse and two batteries. The only remaining
division of Castaños’ ‘Army of the Centre’ consisted of the Murcian
and Valencian corps under Llamas. This had entered Madrid 8,000
strong on August 13, but one of its regiments had been left behind
at Aranjuez to guard the Junta. It now consisted of no more than
7,000 men, and lay at Tudela, in close touch with La Peña’s
Andalusians. The total, therefore, of Castaños’ army in the second
half of October did not amount to more than 31,000 foot and 3,000
horse. The 1st and 3rd divisions of the Andalusian army, long
detained beyond the Morena by the Junta of Seville, were but just
commencing to arrive at Madrid: of their 15,000 men less than half
reached the front in November, in time to take their share in the rout
of Tudela. Even these were not yet at Castaños’ disposition in
October[404].
The right wing of the Spanish army of the Ebro consisted of the
raw and half-organized masses composing the army of Aragon.
Palafox had succeeded in getting together a great body of men from
that loyal province, but he had not been able to form them into a
force fit to take the field. Owing to the way in which Aragon had
been stripped of regular troops before the commencement of the
war, there was no solid body round which the new levies could be
organized, and no supply of trained officers to drill or discipline the
thousands of eager recruits. It would seem that in all no less than
32,000 were raised, but no force in any degree approaching these
numbers took the field. Every village and every mountain valley had
contributed its partida or its company, but with the best of wills
Palafox had not yet succeeded in incorporating all these small and
scattered units into regiments and brigades. Many of them had not
even been armed: very few had been properly clothed and
equipped. Nevertheless no fewer than thirty-nine battalions in a
state of greater or less organization were in existence by the end of
October. They varied in strength to the most extraordinary degree:
many were no more than 300 strong[405], one or two were enormous
and ran up to 1,300 or 1,400 bayonets. Of the whole thirty-nine
battalions only three belonged to the old regular army, and these
corps—whose total numbers only reached 2,350 men—had been
largely diluted with raw recruits[406]. Of the remainder some
belonged to the tercios who had taken arms in June, and had served
through the first siege of Saragossa, but a large number had only
been raised after Verdier had retired from before the city in August.
It would seem that the total of Palafox’s Aragonese, who went to the
front for the campaign of October and November, was about 12,000
men. The rest were left behind at Saragossa, being not yet
organized or equipped for field service.
But Palafox had also in his army troops which did not belong to
his native kingdom. These were the Murcians and Valencians of Saint
March and O’Neille, who after taking part in the campaign against
Moncey, had not marched with Llamas to Madrid, but had turned off
to aid in raising the siege of Saragossa. Saint March had brought
with him fourteen battalions and a cavalry regiment, O’Neille had
with him three more infantry corps. The total of their force reached
11,200 bayonets and 620 sabres. Adding these to the best of his
own Aragonese levies, Palafox sent out 23,000 men: of these only
about 800 were cavalry[407]. A force such as this, backed by the mass
of unorganized levies at Saragossa, was barely sufficient to maintain
a defensive position on the frontiers of Aragon. But the Junta, with
great unwisdom, came to the conclusion that Palafox was strong
enough not only to hold his own against the French in his immediate
front, but to spare some troops to reinforce the army of Catalonia.
By their orders he told off six battalions—some 4,000 men—who
were placed under the command of his brother, the Marquis of
Lazan, and dispatched to Lerida with the object of aiding the
Captain-General of Catalonia to besiege Duhesme in Barcelona.
Nor was this the only force that was drawn off from the main
theatre of the war in order to take part in helping the Catalans, who
had hitherto proved quite strong enough to help themselves. The
Junta directed Reding, the victor of Baylen, to take command of all
the Granadan troops in the army of Andalusia, and lead them to
Tortosa with the object of joining Lazan. With Reding there marched
nearly 15,000 men[408]: to raise this force all the regiments belonging
to the kingdom of Granada had been drafted out from the 1st and
2nd Divisions of Castaños’ army, which were thus mutilated before
they reached the Ebro. To those comparatively veteran troops were
added eight new battalions of raw levies—the regiments of Baza,
Almeria, Loxa, and Santa Fé. Starting on their long march from
Granada on October 8, the head of Reding’s column had only
reached Murcia on October 22, and was thus hopelessly distant from
any point where it could have been useful when the campaign
began[409]. Nor was this the last detachment which the Junta
directed on Catalonia: it sent thither part of the prisoners from
Lisbon, whom the Convention of Cintra had delivered—3,500 of the
men who had once formed the division of Caraffa. Laguna, who now
held the command, landed from English transports at La Rapita near
Tortosa on October 25, and marched from thence on Tarragona[410].
It is safe to say that of these 23,000 men transferred to Catalonia
from Aragon, Granada, and Portugal, every man ought to have been
pushed forward to help Castaños on the Ebro, and not distracted to
the side-issue at Barcelona. It was mad to send them thither when
the main force facing Jourdan and King Joseph did not yet amount
to 75,000 men. Catalonia, with such small aid as the Balearic Islands
could give, was strong enough to defend herself against the motley
hordes of Duhesme and Reille.
At the moment when the feeble offensive of Castaños and Palafox
began, on the line of the Ebro, the French had some 65,000 men
ranged opposite them[411], while a reserve of 10,000 was formed at
Bayonne, and the leading columns of the ‘Grand Army’ from
Germany were only ten or twelve marches away. Napoleon had, by a
decree issued on September 7, recast the form of his army of Spain.
It was in the future to consist of seven army corps. The 1st, 4th, and
5th were to be composed of old divisions from the Rhine and the
Elbe. Of the forces already on the spot Bessières’ troops were to
form the 2nd Corps, Moncey’s the 3rd, the still incomplete divisions
under Ney the 6th. The army of Catalonia, where St. Cyr was
superseding Reille, formed the 7th Corps[412]. Junot’s army from
Portugal, when it once more appeared upon the scene, made the
8th, but in September Napoleon did not yet know of its fate, and it
only received its number and its place in the host at a much later
date. Many alterations of detail were made in the brigades and
divisions that formed the new 2nd and 3rd Corps. All the bataillons
de marche were abolished, and their men drafted into the old
regiments. The fifteen ‘provisional regiments,’ which had composed
the whole of Moncey’s and a considerable part of Bessières’
strength, were taken into the regular establishment of the army, and
renumbered as the 114th-120th of the Line and the 33rd Léger, two
provisional regiments being told off to form each of the new
bodies[413]. There was a certain amount of shifting of units, but in
the main the brigades and divisions of these two corps remained
intact.
On or about October 8-10 Bessières lay at Miranda and Murguia,
guarding against any possible descent of Blake from Villarcayo upon
the Upper Ebro. Ney was at La Guardia, facing Pignatelli’s Castilians,
who occupied his old head quarters at Logroño. Moncey had thrown
back his left to guard against a possible descent of Palafox upon
Navarre, and was behind the line of the river Aragon, with his right
at Estella, his centre at Falces and Tafalla, and his left facing
Sanguesa, where it was opposed by the advanced division of the
army of Palafox under O’Neille. For the Captain-General of Aragon,
pleased with a plan proposed to him by Colonel Doyle, the English
military attaché in his camp, had resolved to make a long turning
movement under the roots of the Pyrenees, exactly parallel to that
which Blake was executing at the other end of the line. With this
object he sent out from Saragossa, on September 29, O’Neille with a
division of Aragonese strengthened by a few Murcian and Valencian
battalions, and numbering some 9,000 bayonets. This detachment,
marching in a leisurely way, reached Sanguesa on the Upper Aragon,
but there stopped short, on getting information that Moncey’s corps
lay before it in some strength. Palafox then sent up in support a
second division, Saint March’s Murcians and Valencians, who
advanced to Egea and there halted. There was considerable
bickering all through the second half of October on this line, but
Sanguesa remained in the hands of the Spaniards, Moncey being too
much distracted by the movements of Castaños in the direction of
Tudela to dare to concentrate his whole force for a blow at Saint
March and O’Neille. The latter, on the other hand, had realized that if
they pressed further forward towards Pampeluna, as their
commander-in-chief had originally intended, they would leave
Moncey so much in their rear that he could cut them off both from
Saragossa and from the Army of the Centre. Here then matters had
come to a deadlock; but the position was all in favour of the French,
who lay compactly in the centre, while O’Neille and Saint March were
separated from Castaños by a gap of sixty miles, and Blake on the
other wing was about seventy (as the crow flies) from the army of
Castile.
SECTION VII: CHAPTER II
THE PRELIMINARY FIGHTING: ARRIVAL OF
NAPOLEON

By the middle of October the French and Spanish armies were in


presence of each other along the whole line of the Ebro, and it
seemed certain that one or other of them must at last take the
offensive. Both were still in expectation of reinforcements, but those
which the Spaniards could expect to receive within the next few
weeks were comparatively unimportant, while their adversaries knew
that more than 100,000 men from Germany were due at Bayonne in
the last days of October. Clearly it was for Castaños and his
colleagues to make a move now or never. The wasted months of
August and September could not be recalled, but there was still time
to attack Bessières, Ney, and Moncey, before the arrival of the
Emperor and the three veteran corps from the Elbe.
Matters lay thus when the Spanish generals resolved on a
perfectly new and wildly impracticable scheme. Castaños had come
to the conclusion—a thoroughly sound one—that his 34,000 men
were too few to make a frontal attack on the French on the line
between Miranda and Calahorra. He left Madrid on October 13,
deeply chagrined to find that the Central Junta had no intention of
making him commander-in-chief. Instead of being able to issue
orders to the other generals, he must meet them on equal terms
and endeavour to cajole them into adopting a common plan of
operations. Accordingly he rode to Saragossa to visit Palafox, and
after long and not very friendly converse drew out a new plan. The
Army of the Centre was to shift itself down the Ebro, leaving the
troops of Pignatelli (the ‘Army of Castile’) and of Grimarest (the 2nd
Andalusian division) to ‘contain’ Ney and Bessières. The rest were to
concentrate at Tudela, where they were to be joined by as many
battalions of the Aragonese levies at Saragossa as could take the
field. With some 25,000 or 30,000 men at the highest estimate,
Castaños and Palafox were to fall upon Moncey’s flank at the bridge
of Caparrosa. Meanwhile O’Neille and Saint March, with the
advanced divisions of the army of Aragon, were to break up from
Sanguesa, march round Pampeluna by the foot-hills of the Pyrenees,
and place themselves across the road to France. Moncey was thus to
be surrounded, and a second Baylen was to ensue! Indeed, if Blake
could be persuaded to push forward once more to Bilbao, and
thence into Guipuzcoa, the whole army of King Joseph (as it was
hoped) might be cut off and made prisoners. Eighty thousand men,
according to this strange scheme, starting from bases 200 miles
apart, were to surround 65,000 French in a most difficult mountain
country. Meanwhile the enormous gap between Blake’s right and
Castaños’ left was to remain wholly unguarded, for the army of
Estremadura was still in the far distance; while nothing was to be
left opposite Bessières and Ney save Pignatelli’s disorderly ‘Army of
Castile,’ and Grimarest’s 6,000 Andalusians.
But before the scheme for the cutting off of Moncey had even
begun to be carried out, Castaños and Palafox had a rude
awakening. They were themselves attacked by the army which they
were so confidently proposing to surround. King Joseph,
emboldened by the long delay of his adversaries in advancing, had
several times discussed with Jourdan, Bessières, and Ney schemes
for taking the offensive. Indeed he had sketched out in September
no less than five separate plans for bringing the enemy to an action,
and it is probable that he might have tried one of them if he had
been allowed a free hand[414]. Napoleon, however, having
determined to come to Spain in person, put an embargo on any
comprehensive scheme for an advance on Madrid, and restricted his
brother to minor operations.
But there was nothing in the Emperor’s instructions which forbade
a blow on a small scale, if the Spaniards should grow too daring.
There was now a good excuse for such a move, for both Pignatelli
and Grimarest had been trespassing beyond the Ebro. They seem to
have moved forward quite contrary to the intentions of Castaños,
who at this moment was proposing to refuse battle with his left and
centre, and to draw the bulk of his army southward to Tudela. But
his two divisional generals pushed so far forward, that they at last
drew upon themselves most undesired attentions from the French
marshals. Pignatelli had thrown troops across the Ebro to Viana:
Grimarest had pushed detachments still further forward into Navarre,
to Mendavia, Sesma, and Lerin. Joseph and Jourdan resolved to
drive back these outlying posts, and to find out what was behind
them. About 25,000 men were put in movement against the 16,000
Spaniards who had so rashly crossed the river. Moncey marched
against Grimarest [Oct. 25-6] with two divisions: Ney with a similar
force fell upon Pignatelli, while Bessières sent a division down the
southern bank of the Ebro by Haro and Briones, to threaten the line
of retreat of the army of Castile across the bridge of Logroño.
Against such forces the Spaniards could do nothing: on the
twenty-fifth Ney marched on Viana, and drove in Pignatelli’s
advanced guard. On the following day he opened a fierce cannonade
upon Logroño from across the river, while at the same time Bonnet’s
division, sent by Bessières, marched upon the town from the hither
side of the Ebro. Pignatelli was a craven, and his Castilian levies
proved to be the worst of all the material which the Spaniards had
brought to the front. General and army vanished in the night,
without even stopping to blow up the great bridge, though they had
mined it and laid the train in due form. Ney’s officers crossing at
dawn found all prepared, except the sappers who should have
applied the match[415]! Neither Ney nor Bonnet got in touch with the
flying horde: but in sheer panic Pignatelli abandoned his guns by the
roadside, and did not stop till he had joined Castaños at Cintruenigo,
near Tudela. His hurried retreat was wholly unnecessary, for the
French did not move beyond Logroño, and Castaños was able to
send out next morning a brigade which picked up the deserted guns
and brought them in without molestation. Rightly indignant, the
Commander-in-chief removed Pignatelli from his post, and
distributed his demoralized battalions among the divisions of
Grimarest, La Peña, and Llamas[416], leaving in separate existence
only a single brigade of six battalions under Cartaojal, which mainly
consisted of the few regular battalions that had been lent to
Pignatelli to stiffen his raw levies. Thus the ‘Army of Castile’ ceased
to exist[417].
On the same day that the Castilians were routed by Ney, the 2nd
Andalusian division was severely handled by Moncey. When that
Marshal advanced against Lerin and Sesma with the divisions of
Morlot and Maurice Mathieu, Grimarest withdrew beyond the Ebro,
abandoning by some oversight his vanguard. This force, commanded
by a resolute officer, Colonel Cruz-Murgeon, was enveloped at Lerin
by the division of Morlot[418]. The colonel shut himself up in the
mediaeval castle of that town, and defended himself for two days, in
hopes that he might be succoured. But his chief had fled beyond the
river, and could not be induced to return by any appeals. On October
27 Cruz-Murgeon had to surrender, after two-thirds of his troops had
been killed or wounded. Their obstinate defence was the more
creditable because they were all new levies, consisting of a single
Andalusian battalion (Tiradores de Cadiz) and a few Catalan
volunteers. Marshal Moncey then occupied Lodosa and its bridge,
but made no attempt to follow Grimarest, who was able to rejoin his
chief without further loss.
Castaños was greatly disturbed by the vigorous offensive
movement of Ney and Moncey. Seeing the French so strong and so
confident, he was struck with sudden qualms as to the advisability of
the movement on Caparrosa and Pampeluna, which he and Palafox
had agreed to carry out. He proposed to his colleague that they
should drop their plan for surrounding Moncey, and attempt no more
than an attack on his flanks at Caparrosa and Sanguesa. Meanwhile
he concentrated the greater part of his army at Calahorra and Tudela
[Oct. 29]. The initiative had passed to the French, and if Ney and
Moncey did not seize the opportunity for an advance against the
Army of the Centre, it was merely because they knew that Napoleon
was now close at hand—he reached Bayonne four days later—and
would not wish them to attempt anything decisive without his
orders.
Meanwhile there arrived from Madrid a deputation from the
Supreme Junta, consisting of Francisco Palafox (the younger brother
of the Captain-General), of Coupigny, Reding’s colleague at the
victory of Baylen, and the intriguing Conde de Montijo. The Junta
were indignant that Castaños had not made bricks without straw.
Though they had not given him any appreciable reinforcements, they
had expected him to attack the French and win a great victory
beyond the Ebro. Conscious that the deputies came to him in no
friendly spirit, Castaños nevertheless received them with all respect,
and laid before them the difficulties of his situation. Joseph Palafox
came up from Saragossa to join the conference, and after a long and
stormy meeting—this was the conference which so disgusted Colonel
Graham[419]—it was decided to resume offensive operations
[November 5]. The idea was a mad one, for six days before the
council of war was held two French army corps, those of Victor and
Lefebvre, had crossed the Bidassoa and entered Spain. There were
now 110,000 instead of 65,000 enemies in front of the Spanish
armies. Moreover, and this was still more important, Napoleon
himself had reached Bayonne on November 3.
Nevertheless it was resolved once more to push forward and fall
upon Moncey. Castaños was to leave one division at Calahorra, and
to bring the rest of his army over the Ebro to attack the bridge of
Caparrosa: O’Neille and Saint March were to come down from
Sanguesa to co-operate with him: Joseph Palafox was to bring up
the Aragonese reserves from Saragossa. The only sign of prudence
that appeared was that the council of war agreed not to commence
the attack on Moncey till they had learnt how Blake and the army of
Galicia were faring in Biscay. For that general had, as they knew,
commenced some days before his second advance on Bilbao. Since
the armies on the Central Ebro hung back, it was in the distant
region on the coast that the first important collision between the
Spaniards and the French reinforcements from Germany was to take
place. For a fortnight more there was comparative quiet in front of
Tudela and Caparrosa. Meanwhile Castaños, prostrated by an attack
of the gout[420], took to his bed, and the Army of the Centre was
abandoned for a few days to the tender mercies of the deputation
from Madrid.
There is a strange contrast when we turn from the study of the
rash and inconsiderate plans of the Spanish generals to mark the
movements of Napoleon. The Emperor had left Erfurt on October 14:
on the nineteenth he had reached Paris, where he stayed for ten
days, busied not only with the ‘logistics’ of moving the columns of
the ‘Grand Army’ across France, but with all manner of
administrative work. He had also to arrange the details of the
conscription: though he had raised in 1807 the enormous mass of
new levies of which we had to speak in an earlier chapter, he now
asked for 140,000 men more[421]. Of these, 80,000 were to be drawn
from the classes of 1806-9, which had already contributed so heavily
to the army. The balance was to be taken from the class of 1810,
whose members were still fifteen months below the legal age. From
these multitudes of young soldiers every regiment of the army of
Spain was to be brought up to full strength, but the majority were
destined to reinforce the depleted armies of Germany and Italy,
which had been thinned of veterans for the Peninsular War.
On October 25 Bonaparte presided at the opening of the
Legislative Assembly, and made a characteristic harangue to its
members. He painted the situation of the Empire in the most roseate
colours. ‘The sight of this great French family, once torn apart by
differences of opinion and domestic hatreds, but now so tranquil,
prosperous, and united, had sensibly touched his soul. To be happy
himself he only required the assurance that France also was happy.
Law, finance, the Church, every branch of the state, seemed in the
most flourishing condition. The Empire was strong in its alliances
with Russia, the Confederation of the Rhine, Denmark, Switzerland,
and Naples. Great Britain, it was true, had landed some troops in the
Peninsula, and stirred up insurrections there. But this was a blessing
in disguise. The Providence which had so constantly protected the
arms of France, had deigned to strike the English ministry with
blindness, and to induce them to present an army on the Continent
where it was doomed to inevitable destruction. In a few days the
Emperor would place himself at the head of his troops, and, with the
aid of God, would crown in Madrid the true King of Spain, and plant
his eagles on the forts of Lisbon[422].’
Four days later Bonaparte quitted Paris, and passing hastily
through Orleans and Bordeaux reached Bayonne at three o’clock in
the morning of November 3. The corps of Victor and Lefebvre, with
two divisions of dragoons, were several days ahead of him, and had
already crossed the Bidassoa. The Imperial Guard and the divisions
destined for Ney[423], as well as a great mass of cavalry, were just
converging on the frontier. Mortier’s corps was not very far off:
Junot’s army from Portugal had already landed at Quiberon and
Rochefort, and was being directed on Bordeaux. All the machinery
for the great blow was now ready.
Napoleon profoundly despised the Spanish army and the Spanish
generals. His correspondence is full of contemptuous allusions to
them: ‘ever since he served at Toulon he knew them for the worst
troops in Europe.’ ‘Nothing could be so bad as the Spaniards—they
are mere rabble—6,000 French can beat 20,000 of them.’ ‘The whole
Spanish army could not turn 15,000 good troops out of a position
that had been properly occupied[424].’ Nevertheless he had
determined to run no risks: the second Peninsular campaign must
not end like the first, in a fiasco and a humiliating retreat. It was for
this reason that the Emperor had massed more than 250,000 good
troops against the tumultuary levies of the Junta—a force which, in
his private opinion, was far more than enough to sweep the whole of
his adversaries into the sea before the year 1808 should have run
out. Any expedition in which he himself took part must, for the sake
of his prestige, be conducted from beginning to end in a series of
spectacular triumphs. It was better to use a larger army than was
absolutely necessary, in order to make his blows sufficiently heavy,
and to get the Spanish business over as rapidly as possible. If the
whole Peninsula were overrun in a few months, and resistance had
been completely beaten down ere the winter was over, there would
be no chance of that intervention on the part of Austria which was
the only danger on the political horizon[425].
Napoleon, therefore, drew out his plans not merely for a
triumphant advance on Madrid, but for the complete annihilation of
the Spanish armies on the Ebro and in Biscay. From a careful study
of the dispatches of his lieutenants, he had realized the existence of
the great gap in the direction of Burgos between the armies of Blake
and of Castaños. His plan of campaign, stated shortly, was to burst
in through this gap, so as to separate the Spanish armies on his left
and right, and then to wheel troops outwards in both directions so
as to surround and annihilate them. Both Blake and Palafox were, at
this moment, playing the game that he most desired. The further
that the former pressed onward into Biscay, the nearer that the
latter drew to the roots of the Pyrenees, the more did they expose
themselves to being encompassed by great masses of troops
breaking out from Burgos and Logroño to fall upon their flank and
rear. When the Emperor drew up his scheme he knew that Blake was
in front of Zornoza, and that the bulk of the army of Aragon was at
Sanguesa. Meanwhile the French advanced divisions were in
possession of Miranda, Logroño, and Lodosa, the three chief
passages over the Upper Ebro. A glance at the map is sufficient to
show that the moment that the Emperor and his reserves reached
Vittoria the Spanish armies were in the most perilous position. It
would suffice to order a march on Burgos on the one hand and on
Tudela on the other, and then the troops of Aragon and Galicia
would not merely be cut off from any possible retreat on Madrid, but
run grave danger of annihilation. A further advance of the French
would probably thrust the one against the Pyrenees, and roll the
other into the Bay of Biscay.
For this reason it was the Emperor’s wish that his lieutenants
should refrain from attacking Blake and Palafox till he himself was
ready to march on Burgos. For any premature advance against the
Spaniards might force them to retreat from their dangerous
advanced positions, and fall back the one on Reynosa the other on
Saragossa, where they would be much less exposed.
The distribution of the ‘Grand Army’ was to be as follows.
Lefebvre with the 4th Corps was to present himself in front of Blake
between Durango and Zornoza, and to hold him fast without
pressing him. Moncey with the 3rd Corps, in a similar way, was to
‘contain’ Palafox and Castaños from his posts at Lodosa, Caparrosa,
and Tafalla. Meanwhile Victor, with the newly arrived 1st Corps, was
to endeavour to get into Blake’s rear, by the road Vittoria—Murguia—
Orduña. The main body of the army, consisting of the troops of
Bessières and Ney, King Joseph’s reserve, the Imperial Guard, and
four divisions of cavalry, was to march on Burgos. Napoleon knew
that there was no large body of Spaniards in that place: he expected
to find there Pignatelli’s ‘Army of Castile,’ but this force (as we have
seen) had ceased to exist, having been drafted with ignominy into
the ranks of the army of Andalusia[426]. As a matter of fact Burgos
was now occupied by a new force from the second line—the long-
expected army of Estremadura, some 12,000 strong, which had at
last come up from Madrid and taken its place at the front. But
Napoleon’s reasoning still held good: any Spanish army that might
chance to be at Burgos must be overwhelmed by the enormous
mass of troops that was about to be hurled upon it. The moment
that it was disposed of, Ney with the 6th Corps was to wheel to the
east, and march by Aranda and Soria, so as to place himself
between Castaños and Palafox and Madrid. Then he would turn their
flank at Tarazona and Tudela, and—in conjunction with Moncey—
drive them northward against the Pyrenees. In a similar way, upon
the other flank, the 2nd Corps was to wheel to the north-west and
march from Burgos on Reynosa, there to intercept Blake, if he had
not already been cut off by Victor’s shorter turning movement.
Meanwhile the Emperor with the rest of his army, followed by the
new reserves (Mortier’s corps and other troops) which were due
from France, would march straight from Burgos on Madrid, force the
defiles of the Somosierra and Guadarrama, and seize the Spanish
capital. He was well aware that there would be no serious hostile
force in front of him, since the armies of Blake, Palafox, and
Castaños were all provided for. He does not seem to have known of
the army of Estremadura, or to have had any idea that the English
forces from Portugal might conceivably be on their way to cover
Madrid. There is no mention of Sir John Moore and his host in the
imperial dispatches till December 5.
All being ready, Bonaparte rode out of Bayonne on November 4,
having stayed there only thirty-six hours. Before leaving he had
received one vexatious piece of news: Lefebvre, in direct
disobedience to his orders, had attacked Blake on October 31, and
forced him back beyond Bilbao. This made the plan for the cutting
off of the army of Galicia a little more difficult, since the Spaniards
were now forty miles further back, and not nearly so much exposed
as they had been hitherto. But it was still not impossible that Victor
might succeed in circumventing them, and forcing them into the Bay
of Biscay.
It is impossible to withhold our admiration from the Emperor’s
simple yet all-embracing plan of operations. It is true that the
campaign was made more easy by the fact that he was dealing with
raw and undisciplined armies and inexpert generals. It is also clear
that he rightly reckoned on having two men in the field against
every one whom the Spaniards could produce. But the excellence of
a scheme is not to be judged merely by the difficulties in its way;
and military genius can be displayed in dealing with an easy as well
as with a dangerous problem. Half a dozen other plans for
conducting the invasion of Spain might have been drawn up, but it is
impossible to see that any better one could have been constructed.
In its main lines it was carried out with complete success: the armies
of the Junta were scattered to the winds, and Madrid fell almost
without a blow.
It was only when the capital had been occupied, and the troops
of Blake and Belvedere, of Castaños and Palafox were flying devious
over half the provinces of Spain, that the difficulties of the
Peninsular War began to develop themselves. Napoleon had never
before had any experience of the character of guerilla warfare, or
the kind of resistance that can be offered by a proud and revengeful
nation which has made up its mind never to submit to the
conqueror. In his complete ignorance of Spain and the Spaniards, he
imagined that he had a very simple campaign to conduct. The
subjugation of the Peninsula was to him an ordinary military
problem, like the invasion of Lombardy or of Prussia, and he went
forth in cheerful confidence to ‘plant the eagles of France on the
forts of Lisbon,’ and to ‘drive the Britannic leopard from the soil of
the Peninsula, which it defiles by its presence.’ But the last chapter
of this story was to be told not at Lisbon but at Toulouse: and ‘the
Beneficent Providence which had deigned to strike the British
ministry with such blindness that they had been induced to send an
army to the Continent[427],’ had other designs than Bonaparte
supposed.
SECTION VII: CHAPTER III
THE MISFORTUNES OF JOACHIM BLAKE: ZORNOZA
AND ESPINOSA DE LOS MONTEROS

The campaign of November 1808 was fought out upon three


separate theatres of war, though every movement of the French
armies which engaged in it formed part of a single plan, and was
properly linked to the operations which were progressing upon other
sections of the front. The working out of Napoleon’s great scheme,
therefore, must be dealt with under three heads—the destruction of
Blake’s ‘Army of the Left’ in the north-west; the rout of the armies of
Andalusia and Aragon upon the banks of the Ebro; and the central
advance of the Emperor upon Burgos and Madrid, which completed
the plan.
We must first deal with the misfortunes of Blake and his Galician
host, both on chronological grounds—it was he who first felt the
weight of the French arms—and also because Napoleon rightly
attached more importance to the destruction of this, the most
formidable of the Spanish armies, than to the other operations which
he was carrying out at the same moment.
It will be remembered that after his first abortive expedition
against Bilbao, and his retreat before Ney [October 5], Blake had
fallen back to Valmaceda. Finding that he was not pursued, he drew
up to that point the divisions which he had hitherto kept in the upper
valley of the Ebro, and prepared to advance again, this time with his
whole army massed for a bold stroke. On October 11 he again
marched into Biscay, and drove out of Bilbao the division of General
Merlin, which Ney had left behind him to hold the line of the
Nervion. On the twelfth this small force fell back on Zornoza and
Durango, and halted at the latter place, after having been reinforced
from King Joseph’s reserve at Vittoria. Verdier headed the succours,
which consisted of three battalions of the Imperial Guard, two
battalions of the 118th Regiment, two battalions of Joseph’s own
Royal Guards, and the 36th Regiment, which had just come up from
France. When strengthened by these 7,000 men, Merlin considered
himself able to make a stand, and took up a strong position in front
of Durango, the important point at which the roads from Bayonne
and from Vittoria to Bilbao meet.
When committing himself to his second expedition into Biscay,
Blake was not wholly unaware of the dangers of the step, though he
failed to realize them at their full value, since (in common with the
other Spanish generals) he greatly underrated the strength of the
French army on the Ebro. He intended to carry out his original plan
of cutting off Bessières and King Joseph from their retreat on
Bayonne, by forcing the position of Durango, and seizing the high-
road at Bergara; but he was aware that an advance to that point had
its dangers. As long as his divisions had lain in or about Villarcayo
and Valmaceda, he had a perfectly clear line of retreat westward in
the event of a disaster. But the moment that he pushed forward
beyond Bilbao, he could be attacked in flank and rear by any troops
whom the King might send up from the valley of the Ebro, by the
two mountain-roads which run from Vittoria to the Biscayan capital.
One of these is the main route from Vittoria to Bilbao via Murguia
and Orduña. The other is a more obscure and difficult path, which
leads across the rough watershed from Vittoria by Villareal and
Villaro to Bilbao. Aware of the fact that he might be assailed by
either of these two passes, Blake told off a strong covering force to
hold them. Half of Acevedo’s Asturian division, 4,000 strong, was
placed at Orduña: the other half, with the whole of Martinengo’s 2nd
Division of Galicia, 8,500 bayonets in all, took its post in the direction
of Villaro. These detachments were eminently justifiable, but they
had the unfortunate result of enfeebling the main force that
remained available for the stroke at the French in front of Durango.
For that operation Blake could only count on his 1st, 3rd, and 4th
Divisions, as well as the ‘Vanguard’ and ‘Reserve’ Brigades—a total
of 18,000 men[428].
Blake had seized Bilbao on October 11: it is astonishing therefore
to find that he made no forward movement till the twenty-fourth. By
this sluggishness he sacrificed his chance of crushing Merlin before
he could be reinforced, and—what was far worse—allowed the
leading columns of the ‘Grand Army’ to reach Irun. If he had pressed
forward on the twelfth or thirteenth, they would still have been
many marches away, trailing across Guyenne and Gascony. Having
once put his hand to such a dangerous manœuvre as that of
pushing between the French flank and the northern sea, Blake was
most unwise to leave the enemy time to divine his object and to
concentrate against him. A rapid stroke at Durango and Bergara, so
as to cut the great high-road to France in the rear of Bessières, was
his only chance. Such an attempt would probably have landed him in
ultimate disaster, for the enemy (even before the ‘Grand Army’
arrived) were far more numerous than he supposed. He had valued
them at 40,000 men, while they were really 64,000 strong. But
having framed the plan, he should at least have made a strenuous
attempt to carry it out. It is possible to explain but not to excuse his
delay: his army was not equipped for a winter campaign, and the
snow was beginning to lie on the upper slopes of the Cantabrian hills
and the Pyrenees. While he was vainly trying to obtain great-coats
and shoes for his somewhat tattered army, from the Central Junta or
the English, and while he was accumulating stores in Bilbao, the
days slipped by with fatal rapidity.
It was not till October 24 that he at last moved forward from
Bilbao, and committed himself to the now hopeless task of clearing
the way to Durango and Bergara. On that day his advanced guard
drove Merlin’s outlying posts from their positions, and came face to
face with the French main body, drawn out on the hillsides of
Baquijano, a few miles in front of Durango. The enemy expected him
to attack next day, but he had just received confused notices from
the peasantry to the effect that enormous reinforcements had
reached Irun and San Sebastian, and were within supporting
distance of the comparatively small force with which he had hitherto
been dealing. This information threw him back into the condition of
doubt and hesitation from which he had for a moment emerged, and
he proceeded to halt for another full week in front of the Durango
position. Yet it was clear that there were only two rational
alternatives before him: one was to attack Merlin and Verdier before
they could draw succour from the newly arrived corps. The other
was to fall back at once to a position in which he could not be
enveloped and outflanked, i.e. to retire behind Bilbao, holding that
town with nothing more than a small detachment which could easily
get away if attacked. But Blake did nothing, and waited in the
supremely dangerous post of Zornoza, in front of Durango, till the
enemy fell upon him at his leisure.
The troops whose arrival at Irun had been reported consisted of
the two leading divisions of the 4th Corps, that of Lefebvre, and of
the whole of the 1st Corps, that of Victor. The former, arriving as
early as October 18, only seven days after Blake captured Bilbao,
marched westward, and replaced Merlin and Verdier in the Durango
position. The troops of these two generals were directed by King
Joseph to rejoin their proper commanders when relieved, so Verdier
led the Guards back to the central reserve, while Merlin reported
himself to Ney, at La Guardia. To compensate Lefebvre for their
departure, and for the non-arrival of his third division, that of
Valence, which still lay far to the rear, Villatte’s division of the 1st
Corps was sent to Durango. Marshal Victor himself, with his other
two divisions, took the road to Vittoria, and from thence, at the
King’s orders, transferred himself to Murguia, on the cross-road over
the mountains to Bilbao. Here he was in a position to strike at
Blake’s rear, after driving off the 4,000 men of Acevedo’s Asturian
division, who (as it will be remembered) had been told off by the
Spanish General to cover this road[429].
King Joseph, inclining for once to a bold stroke, wished to push
Victor across the hills on to Bilbao, while Lefebvre should advance
along the high-road and drive Blake into the trap. Bessières at the
same moment might move a division by Orduña and Oquendo, and
place himself at Valmaceda, which Blake would have to pass if he
escaped from Victor at Bilbao. This plan was eminently sound, for
there was no doubt that the two marshals, who had at their disposal
some 35,000 men, could easily have brushed out of their way the
two divisions under Acevedo and Martinengo which Blake had left
behind him in the passes. Nothing could have prevented them from
seizing Bilbao and Valmaceda, and the Spanish army would have
been surrounded and captured. At the best some part of it might
have escaped along the coast-road to Santander, if its commander
detected ere it was too late the full danger of his position.
This scheme, however, was not carried out: Bessières, Victor, and
Ney showed themselves opposed to it: Napoleon had announced
that he intended ere long to appear in person, and that he did not
wish to have matters hurried before his arrival. His obsequious
lieutenants refused to concur in any great general movement which
might not win his approval. Victor, in particular, urged that he had
been ordered to have the whole of the 1st Corps concentrated at
Vittoria, and that if he marched northward into Biscay he would be
violating his master’s express command[430]. Joseph and Jourdan,
therefore, resolved to defer the execution of their plan for the
annihilation of Blake, and sent orders to Lefebvre to maintain his
defensive position at Durango, and make no forward movement. In
so doing they were acting exactly as the Emperor desired.
They had forgotten, however, to reckon with the personal
ambition of the old Duke of Dantzig. Lefebvre, in spite of his many
campaigns, had never before had the chance of fighting on his own
account a pitched battle of the first class. The Spanish army had
been lying before him for a week doing nothing, its commander
being evidently afraid to attack. Its force was not very great—indeed
it was outnumbered by that of the Marshal whose three divisions
counted not less than 21,000 bayonets[431]. Noting with the eye of an
old soldier Blake’s indecision and obvious timidity, he could not resist
the temptation of falling upon him. Notwithstanding the King’s
orders, he resolved to strike, covering his disobedience by a futile
excuse to the effect that he had observed preparations for taking the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like