Learning PHP, Mysql & Javascript, 7Th Edition Robin Nixon
Learning PHP, Mysql & Javascript, 7Th Edition Robin Nixon
com
https://ebookmeta.com/product/learning-php-mysql-
javascript-7th-edition-robin-nixon/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/php-mysql-novice-to-ninja-7th-edition-
tom-butler/
ebookmeta.com
https://ebookmeta.com/product/php-and-mysql-174-web-development-luke-
welling/
ebookmeta.com
https://ebookmeta.com/product/biblical-a-story-of-a-flying-beast-an-
untold-american-folktale-2023rd-edition-katyas-mom/
ebookmeta.com
Lovecraftiana The Magazine of Eldritch Horror 2016 17 1st
Edition Rogue Planet Press Joseph Rubas Seamus Esparza
Carl Fox Benjamin Welton Sandro D Fossemo Franklyn
Searight John C Adams Gary Budgen Dj Tyrer
https://ebookmeta.com/product/lovecraftiana-the-magazine-of-eldritch-
horror-2016-17-1st-edition-rogue-planet-press-joseph-rubas-seamus-
esparza-carl-fox-benjamin-welton-sandro-d-fossemo-franklyn-searight-
john-c-adams-gary-budgen-dj/
ebookmeta.com
https://ebookmeta.com/product/insight-guides-arizona-the-grand-canyon-
travel-guide-ebook-5th-edition-insight-guides/
ebookmeta.com
https://ebookmeta.com/product/little-stars-ballet-taylor-farley/
ebookmeta.com
With Early Release ebooks, you get books in their earliest form—the author’s raw and
unedited content as they write—so you can take advantage of these technologies long before
the official release of these titles.
Robin Nixon
Learning PHP, MySQL & JavaScript
by Robin Nixon
Copyright © 2024 Robin Nixon. 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://oreilly.com). For more information, contact our
corporate/institutional sales department: 800-998-9938 or [email protected].
Copyeditor: TO COME
Proofreader: TO COME
Indexer: TO COME
The World Wide Web is a constantly evolving network that has already traveled far beyond its
conception in the early 1990s, when it was created to solve a specific problem. State-of-the-art
experiments at CERN (the European Laboratory for Particle Physics, now best known as the
operator of the Large Hadron Collider) were producing incredible amounts of data—so much
that the data was proving unwieldy to distribute to the participating scientists, who were spread
out across the world.
At this time, the internet was already in place, connecting several hundred thousand computers,
so Tim Berners-Lee (a CERN fellow) devised a method of navigating between them using a
hyperlinking framework, which came to be known as Hypertext Transfer Protocol, or HTTP. He
also created a markup language called Hypertext Markup Language, or HTML. To bring these
together, he wrote the first web browser and web server.
Today we take these simple tools for granted, but back then, the concept was revolutionary. The
most connectivity so far experienced by at-home modem users was dialing up and connecting to
a bulletin board where you could communicate and swap data only with other users of that
service. Consequently, you needed to be a member of many bulletin board systems in order to
effectively communicate electronically with your colleagues and friends.
But Berners-Lee changed all that in one fell swoop, and by the mid-1990s, there were three
major graphical web browsers competing for the attention of five million users. It soon became
obvious, though, that something was missing. Yes, pages of text and graphics with hyperlinks to
take you to other pages was a brilliant concept, but the results didn’t reflect the instantaneous
potential of computers and the internet to meet the particular needs of each user with
dynamically changing content. Using the web was a very dry and plain experience, even if we
did now have scrolling text and animated GIFs!
Shopping carts, search engines, and social networks have clearly altered how we use the web. In
this chapter, we’ll take a brief look at the various components that make up the web, and the
software that helps make using it a rich and dynamic experience.
NOTE
It is necessary to start using some acronyms more or less right away. I have tried to clearly explain
them before proceeding, but don’t worry too much about what they stand for or what these names
mean, because the details will become clear as you read on.
Using PHP
With PHP, it’s a simple matter to embed dynamic activity in web pages. When you give pages
the .php extension, they have instant access to the scripting language. From a developer’s point
of view, all you have to do is write code such as the following:
<?php
echo "Today is " . date("l") . ". ";
?>
The opening <?php tells the web server to allow the PHP program to interpret all the following
code up to the ?> tag. Outside of this construct, everything is sent to the client as direct HTML.
So, the text Here's the latest news. is simply output to the browser; within the PHP
tags, the built-in date function displays the current day of the week according to the server’s
system time.
The final output of the two parts looks like this:
PHP is a flexible language, and some people prefer to place the PHP construct directly next to
PHP code, like this:
There are even more ways of formatting and outputting information, which I’ll explain in the
chapters on PHP. The point is that with PHP, web developers have a scripting language that,
although not as fast as compiling your code in C or a similar language, is incredibly speedy and
also integrates seamlessly with HTML markup.
NOTE
If you intend to enter the PHP examples in this book into a program editor to follow along with me,
you must remember to add <?php in front and ?> after them to ensure that the PHP interpreter
processes them. To facilitate this, you may wish to prepare a file called example.php with those tags in
place.
Using PHP, you have unlimited control over your web server. Whether you need to modify
HTML on the fly, process a credit card, add user details to a database, or fetch information from
a third-party website, you can do it all from within the same PHP files in which the HTML itself
resides.
Using MySQL
Of course, there’s not a lot of point to being able to change HTML output dynamically unless
you also have a means to track the information users provide to your website as they use it. In the
early days of the web, many sites used “flat” text files to store data such as usernames and
passwords. But this approach could cause problems if the file wasn’t correctly locked against
corruption from multiple simultaneous accesses. Also, a flat file can get only so big before it
becomes unwieldy to manage—not to mention the difficulty of trying to merge files and perform
complex searches in any kind of reasonable time.
That’s where relational databases with structured querying become essential. And MySQL, being
free to use and installed on vast numbers of internet web servers, rises superbly to the occasion.
It is a robust and exceptionally fast database management system that uses English-like
commands.
The highest level of MySQL structure is a database, within which you can have one or more
tables that contain your data. For example, let’s suppose you are working on a table called users,
within which you have created columns for surname, firstname, and email, and you now wish to
add another user. One command that you might use to do this is as follows:
You will previously have issued other commands to create the database and table and to set up
all the correct fields, but the SQL INSERT command here shows how simple it can be to add
new data to a database. SQL is a language designed in the early 1970s that is reminiscent of one
of the oldest programming languages, COBOL. It is well suited, however, to database queries,
which is why it is still in use after all this time.
It’s equally easy to look up data. Let’s assume that you have an email address for a user and need
to look up that person’s name. To do this, you could issue a MySQL query such as the following:
MySQL will then return Smith, John and any other pairs of names that may be associated
with that email address in the database.
As you’d expect, there’s quite a bit more that you can do with MySQL than just simple INSERT
and SELECT commands. For example, you can combine related data sets to bring related pieces
of information together, ask for results in a variety of orders, make partial matches when you
know only part of the string that you are searching for, return only the nth result, and a lot more.
Using PHP, you can make all these calls directly to MySQL without having to directly access the
MySQL command-line interface yourself. This means you can save the results in arrays for
processing and perform multiple lookups, each dependent on the results returned from earlier
ones, to drill down to the item of data you need.
For even more power, as you’ll see later, there are additional functions built right into MySQL
that you can call up to efficiently run common operations within MySQL, rather than creating
them out of multiple PHP calls to MySQL.
Using JavaScript
JavaScript was created to enable scripting access to all the elements of an HTML document. In
other words, it provides a means for dynamic user interaction such as checking email address
validity in input forms and displaying prompts such as “Did you really mean that?” (although it
cannot be relied upon for security, which should always be performed on the web server).
Combined with CSS (see the following section), JavaScript is the power behind dynamic web
pages that change in front of your eyes rather than when a new page is returned by the server.
However, JavaScript used to be tricky to use, due to some major differences in the ways different
browser designers have chosen to implement it. This mainly came about when some
manufacturers tried to put additional functionality into their browsers at the expense of
compatibility with their rivals.
Thankfully, the developers have mostly come to their senses and have realized the need for full
compatibility with one another, so it is less necessary these days to have to optimize your code
for different browsers. However, there remain millions of users using legacy browsers, and this
will likely be the case for a good many years to come. Luckily, there are solutions for the
incompatibility problems, and later in this book we’ll look at libraries and techniques that enable
you to safely ignore these differences.
For now, let’s take a look at how to use basic JavaScript, accepted by all browsers:
<script type="text/javascript">
document.write("Today is " + Date() );
</script>
This code snippet tells the web browser to interpret everything within the <script> tags as
JavaScript, which the browser does by writing the text Today is to the current document,
along with the date, using the JavaScript function Date. The result will look something like this:
NOTE
Unless you need to specify an exact version of JavaScript, you can normally omit the
type="text/javascript" and just use <script> to start the interpretation of the JavaScript.
As previously mentioned, JavaScript was originally developed to offer dynamic control over the
various elements within an HTML document, and that is still its main use. But more and more,
JavaScript is being used for Ajax, the process of accessing the web server in the background.
Asynchronous communication is what allows web pages to begin to resemble standalone
programs, because they don’t have to be reloaded in their entirety to display new content.
Instead, an asynchronous call can pull in and update a single element on a web page, such as
changing your photograph on a social networking site or replacing a button that you click with
the answer to a question. This subject is fully covered in Chapter 17.
Other documents randomly have
different content
— Mets ton chapeau et allons au Bois.
Dans la forêt, nous jouâmes à nous enterrer sous les feuilles
mortes : ils m’avaient enfouie toute, sauf la tête. Jantje voulait être
enfoui à côté de moi.
Mon ami se mit, devant nous, à rire de son beau rire espiègle et
à marcher de long en large, puis à s’éloigner un grand bout et à
nous terrifier en nous disant qu’il nous abandonnerait là toute la
nuit… puis que j’en avais une touche sous ces feuilles, avec mes
bandeaux et ma capote bleue… Et de pouffer et de nous dire que
nous lui rappelions les Contes d’Hoffmann…
Nous rentrions de ces excursions avec le bonheur incrusté en
nous. Tout passe, tout casse, mais tout ne lasse pas. Ces heures
divines !…
Nous étions entrés chez la petite femme pour boire du lait. Mileke
s’empara de Jantje et le conduisit dans une étable pour lui montrer
les génisses et aussi un petit veau qui leur était né la nuit.
— Tante, il y a trois petites vaches qui commencent à avoir des
cornes, et une toute petite qui n’en a pas encore et qui tète les
doigts de Mileke. Et Mileke a aussi une boîte avec des bêtes qui font
de la soie : connais-tu ça, tante ?
— Oui, mon grand.
— Il va m’en donner une dans une autre boîte que je pourrai
emporter, et la bête fera de la soie. Tu en feras une robe, tante ?
Mileke regardait Jantje, tout ébahi, ne comprenant point qu’il ne
connût pas toutes ces choses, toutes ces merveilles qui le faisaient,
lui, palpiter du matin au soir et la nuit dans ses rêves. Et le petit
garçon en guenilles avait pitié du petit qui lui représentait le riche et
qui n’avait pas tout cela.
— Je puis aussi te montrer nos pigeons et des nids d’oiseaux
avec des œufs.
Et il l’emmena. Je rejoignis la petite femme. Le fils aîné, frère de
la Doctrine Chrétienne, venait d’arriver en vacances. Embarrassé
devant la dame étrangère, il s’assit, le chapeau sur la tête. Jantje
entra en bombe.
— Tante ! j’ai vu un nid avec de tout petits oiseaux, et la mère
voulait nous mordre. Et voilà un nid avec des œufs.
Il me mit le nid sur les genoux.
— Oh ! Jan, il faut rapporter ce nid : les petits oiseaux ne pourront
naître, puisque la mère ne peut s’étendre sur les œufs pour les
couver. Va rapporter ce nid.
— Mais tante !
— Mon grand, ils mourront, les œufs doivent avoir la chaleur de
la mère pour éclore. Va, chéri, mais donne d’abord la main à
monsieur.
Alors seulement il vit le frère. Mais au lieu d’aller vers lui, il se
blottit contre moi.
— Eh bien, Jantje, donne la main à monsieur.
— Mais, tante, ce n’est pas un monsieur : il a une robe.
Le petit frère rit, mais devint rouge jusque derrière les oreilles. Je
n’arrivai pas à persuader Jantje.
Il me répéta :
— Ce n’est pas un monsieur, il a une robe, et ce n’est pas une
dame, il a rasé sa barbe.
Pour échapper à l’antipathie que lui inspirait le frère, il reprit le nid
et se sauva, disant :
— Je vais le rapporter.
— Il serait difficile de réduire ce caractère, me dit le petit frère,
mais si je l’avais dans ma classe, ce serait cependant vite fait.
Jantje ne revenait pas. Mileke vint pousser la tête de derrière la
porte, qu’il entrebâilla, regarda son grand frère, puis la retira vite.
J’allai vers la porte ; Jantje ne voulait pas rentrer, de terreur de
l’homme en robe. Je criai au revoir à la petite femme et à son fils, et
Jantje, serrant dans une main la boîte avec le ver à soie, s’accrocha
de l’autre à la mienne.
— Tante, il ne va pas venir, le monsieur en robe ?
Juillet 1915.
30 mai, 1916.
Quelle calamité !
La semaine passée, j’ai lavé la tête des deux plus jeunes fillettes
de la petite femme : deux adorables petites créatures de cinq et dix
ans, fines, intelligentes, exquises. Quelques jours après, afin qu’elles
puissent dorénavant soigner elles-mêmes leurs cheveux, je leur ai
acheté une brosse et leur ai brossé la tête pour montrer à l’aînée,
Mitje, qui a dix-sept ans, comment elle doit faire. Puis j’ai noué un
ruban blanc dans leurs cheveux. Elles avaient des figures d’ange
spirituel. Après, je m’assis avec Fineke, la plus petite, contre moi, la
mère et les autres enfants se tenant debout. Tout en expliquant à la
mère et à l’aînée qu’il fallait aussi qu’elles se lavent et se brossent la
tête, j’aperçus des poussières qui se mouvaient sur mon corsage et
le devant de ma jupe. Je pris mon face-à-main et vis que j’étais
couverte de poux. « Mon Dieu, voyez, fis-je. » Alors toute la famille
se mit à me les ôter et à les écraser entre les ongles des pouces. La
mère et l’aînée s’écriaient : « Cela doit justement arriver à madame
qui est tellement contre les poux ! » Et elles les prenaient. Le petit
garçon en prit, Anneke en prit, agenouillée devant moi, Fineke les
montrait de ses petits doigts, disant : « Là, encore une grosse bête. »
Ils n’étaient pas plus honteux que si un peu de poussière de l’âtre
m’était volée sur la robe.
Enfin, les bêtes furent enlevées, et l’on me donna un coup de
brosse. Alors je galopai jusque chez moi.
— Emma ! Emma ! vite une autre robe, et brossez celle-ci
d’importance, et de l’eau chaude pour mes mains, et voyez s’il n’y a
pas de poux sur ma robe.
— Des poux, madame ?
Je lui racontai la chose.
— Ne dites rien à Trinette, elle le colporterait par tout le village.
Puis je courus brosser, mais là brosser mes cheveux — me
voyez-vous avec de la vermine dans mes cheveux blancs ? — et me
laver les mains avec de l’eau chaude.
La petite femme a été élevée par une marâtre qui passait sa vie
à l’église, qui ne s’occupait pas d’elle et la laissait courir les champs,
couverte de vermine et de saleté. A l’école, m’a-t-on dit, elle
contaminait toutes ses camarades. Mais le mal n’est pas tant là —
des pouilleux, il y en a partout, — le mal est qu’en Campine vous
êtes des gens sans tache du moment que vous priez, et que ces
paysans, éloignés de tout centre de civilisation, sont livrés pieds et
mains liés au curé, à peine débarrassé lui-même de ses poux. Le
soir, en passant par les rues des villages, vous entendez la voix du
père ou de la mère réciter les litanies et toute la famille répondre :
« Priez pour nous », au lieu qu’on décrasse les enfants avant de les
mettre au lit. Quand vous vous adonnez à ces pratiques, vous êtes
bien vu du curé et de tout le pays : tout le reste de la vie est détail.
Il y a trois ans, en arrivant ici au printemps, je vis Anneke dans la
cour de la ferme, amaigrie, pâle, la tête entre les épaules,
grincheuse et tremblotante, le crâne, les oreilles et la moitié des
joues envahies d’une croûte formée par ses cheveux et la sanie
coulant des plaies où grouillaient des légions de poux.
— Qu’est-ce que c’est que cela ? fis-je à la mère.
— Elle est ainsi depuis tout l’hiver, répondit-elle naïvement ; et les
sœurs se plaignent qu’elle n’apprend plus.
— Mais ce n’est que de la saleté, vous n’aviez qu’à la laver.
— Vous croyez ? Les voisines disent que c’est mauvais de faire
partir cela.
— Mauvais ! vous allez voir ça.
Et j’emmenai la petite. J’avais déjà envoyé une servante pour
tout apprêter. Je commençai par imbiber d’huile la tête de l’enfant,
puis je lui détachai doucement les croûtes et coupai impitoyablement
toute la carapace, morceau par morceau. Anneke hurla tout le temps
de l’opération. La puanteur était intolérable. Je brûlais à mesure que
je détachais ; ma servante se tenait, dégoûtée, à distance.
— C’est sale, n’est-ce pas, Hortense ?
— Oh ! je n’y mettrais tout de même pas les mains.
— Non, vous laisseriez l’enfant pourrir et s’idiotiser sous cette
carapace de poux et de pus. Donnez-moi de l’eau chaude.
Je mis un peu de sel de soude dans l’eau très chaude, et, avec
un gant de toilette et du savon noir, je lavai longuement et
doucement la tête, puis la rinçai deux fois dans de l’eau chaude
bouillie et boriquée ; j’essuyai doucement d’un fin linge, donnai des
bonbons à l’enfant, et par le soleil brûlant, sans couvrir la tête, je la