PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP...
-
Upload
magnus-shields -
Category
Documents
-
view
226 -
download
3
Transcript of PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP...
![Page 1: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/1.jpg)
PHP: Hypertext ProcessorINTEGRATING with MySQL
Stratford Technologies,
Inc.
by Bill PattersonPHP is an open source object oriented scripting/programming language with
strong database capability. It is a project of the Apache Foundation.
MySQL is a relational database management system. Its source is available for free. It is a product of
MySQL AB, a Swedish company.
by Bill PattersonPHP is an open source object oriented scripting/programming language with
strong database capability. It is a project of the Apache Foundation.
MySQL is a relational database management system. Its source is available for free. It is a product of
MySQL AB, a Swedish company.
![Page 2: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/2.jpg)
LAMP
LinuxApacheMySQLPHP
![Page 3: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/3.jpg)
Linux
We know that.Examples today will use Red Hat at a
hosting service
![Page 4: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/4.jpg)
Apache
Apache [HTTP Server] has been the most popular web server on the Internet since April of 1996. The July 2003 Netcraft Web Server Survey found that 63% of the web sites on the Internet are using Apache, thus making it more widely used than all other web servers combined. -- http://www.apache.org
The Apache HTTP Server is a project of the Apache Software Foundation.
![Page 5: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/5.jpg)
Apache, continued
“The Apache Software Foundation provides support for the Apache community of open-source software projects. The Apache projects are characterized by a collaborative, consensus based development process, an open and pragmatic software license, and a desire to create high quality software that leads the way in its field. We consider ourselves not simply a group of projects sharing a server, but rather a community of developers and users.” -- http://www.apache.org
a ‘patchy’ server “The Apache HTTP Server Project is an effort to develop and
maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.” -- http://httpd.apache.org
![Page 6: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/6.jpg)
MySQL
“MySQL is the world's most popular open source database, recognized for its speed and reliability. MySQL AB, the company founded by the creators of the MySQL database, provides MySQL software development and related support and services.” -- http://www.mysql.com
MySQL AB operates according to a business model that supports both profit and open source.
More later.
![Page 7: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/7.jpg)
PHP
“PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.” -- http://www.php.net
![Page 8: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/8.jpg)
PHP , continued
The easiest “Hello World” ever, according to its initial developer, Rasmus Lerdorf
“Hello World” and you don’t even have to include the quotes [bill@lynx bill]$ php Hello World! Content-type: text/html X-Powered-By: PHP/4.3.2
Hello World! [bill@lynx bill]$
![Page 9: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/9.jpg)
PHP, continued
“PHP began as a simple macro replacement tool. … On the hyperspeed development track of the Internet, PHP has become the equivalent of a 1960s muscle car. It’s cheap, it’s fast, and there’s plenty of room under the hood for you and your virtual wrench.” Core PHP Programming by Leon Atkinson
![Page 10: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/10.jpg)
PHP Overview
PHP works on multiple platforms Linux and other Unices Windows
When providing Linux Web service, PHP lives in the Apache HTTP Server, connects to favorite database management systems, reads and writes files, and especially likes to read posted variables and write HTML (and JavaScript) to web browsers.
![Page 11: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/11.jpg)
PHP Overview , continued
I describe PHP as what you get if you tear apart C++ and Perl, toss the pieces in the air, and scoop the crumbs off the floor. Object oriented, C++ like programming
language with extensive string manipulation capability and dynamic variables that all begin with a dollar sign (‘$’).
The latest release as of 30 July 2003 is PHP 4.3.3RC2 (“should be nearly bug free”).
![Page 12: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/12.jpg)
PHP Features & Benefits
Interpretive (almost) Actually, a just-in-time compile occurs
when PHP pages are accessed
It can be encoded so that your source remains unavailable to the observer
Object oriented facilitates code reuse
Variable names begin with a dollar sign
![Page 13: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/13.jpg)
PHP More Benefits
String types - many string functionsAll arrays are sparse (aka hash) -
and you don’t have to pre-define them (and therefore may use alphanumeric indices)
Fully capable programming languageShort time to deployment
![Page 14: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/14.jpg)
PHP Web Applications
Web sites Forms that receive and enable
processing of information Content management Personalization Can be very elaborate
Bulletin board Phorum available from http://phorum.org/
![Page 15: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/15.jpg)
PHP Web Applications, continued
Fast Template approach to separate the management of the
HTML and the programming in PHP a mixed blessing if you are interested:
http://www.thewebmasters.net/
![Page 16: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/16.jpg)
PHP Batch Applications
String and database capabilities make PHP a natural for some batch applications as well as web applications
Examples Screen scaping and emailing SSL data retrieval Data base maintenance
![Page 17: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/17.jpg)
PHP Session Management
Enables stateful processingWill use cookies if available, otherwise
stores session identification (and other variables) in URL
maintains session data on the serverUseful for maintaining a dialog with the
users without having to send data back and forth all the time between screens
![Page 18: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/18.jpg)
PHP Session management, continued
Can manage sessions without cookies and still use POSTed data (avoiding extensive URLs), but it is tricky as you need to keep the POSTed data alive.
![Page 19: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/19.jpg)
PHP Pricing
FREE
![Page 20: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/20.jpg)
PHP Availability
Directly off the web at www.php.net along with much information about it
Other RDBMSs can also connect. PostgreSQL Oracle MS SQL Server
![Page 21: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/21.jpg)
PHP Web Hosting
Check online for host services and reviews http://www.webhostdir.com/ http://www.findmyhost.com/ http://www.hostsearch.com/ http://www.hostspot.com/
![Page 22: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/22.jpg)
PHP Web Hosting, continued
I use http://www.phpwebhosting.com/
![Page 23: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/23.jpg)
PHP Web References
http://www.php.net/ (the official site) http://www.nyphp.org/ http://www.php-con.com/ http://www.devshed.com/ http://www.phpbuilder.com/ http://www.phpusergroups.org/ http://www.phpwizard.net/ http://www.weberdev.com/ http://hotwired.lycos.com/webmonkey/programming/php/
index.html
![Page 24: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/24.jpg)
PHP Book References
Atkinson, Leon: Core PHP ProgrammingCastagnetto, Jesus et al: Professional
PHP ProgrammingGreenspan, Jay and Brad Bulger:
MySQL/PHP Database Applications (disclosure [or shameless plug]…I am tech-editor of the 2nd edition)
Meloni, Julie: PHP Fast and Easy Development
![Page 25: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/25.jpg)
MySQL (no one knows for sure where the name originated, there’s a couple of ideas)
“The derivation of the name MySQL is not clear. Our base directory and a large number of our libraries and tools have had the prefix ‘my’ for well over 10 years. However, co-founder Monty Widenius's daughter (some years younger) is also named My. Which of the two gave its name to MySQL is still a mystery, even for us.” -- MySQL AB
![Page 26: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/26.jpg)
MySQL
A relational database management system provides a means of storing and retrieving data according to a standard structure
Why a database? Because
Problems will be solved before they occur• But not the ones you were thinking of, and there will be
other problems but generally not as bad
Applications will benefit for years to come
![Page 27: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/27.jpg)
MySQL
What is a relational database? Dr. E. F. Codd’s A Relational Model of Data
for Large Shared Databanks, 1970 “The relational model is simple and elegant
with sound underlying theory based on concepts of relational algebra and first order predicate calculus.” (--Daniela Rosu)
Looks at the universe as consisting of tables, which in turn consist of rows and columns.
![Page 28: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/28.jpg)
MySQL
Structured Query Lnaguagespecifies operations among tables’ rows and
columnsstandardized by ISOprovides for
• INSERT• UPDATE• DELETE• SELECTion
and much more
![Page 29: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/29.jpg)
MySQL
Relational Database Design Principles - Normalize - too brief a summary Eliminate Repeating Groups Eliminate Redundant Data Eliminate Columns not Dependent on the Key Perhaps...Isolate Independent Multiple
Relationships Perhaps...Isolate Semantically Related Multiple
Relationships
![Page 30: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/30.jpg)
MySQL
“The rules leading to and including the third normal form can be summed up in a single statement: Each attribute must be a fact about the key, the whole key, and nothing but the key” -- Wiorkowski and Kull, DB2 Design & Development Guide
![Page 31: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/31.jpg)
MySQL
Why normalize? “Normalization carries a number of
benefirts. One of the most important is that its rules
reduce data redundancy, in the process ensuring the data’s consistency by allowing for efficient, accurate updates and deletions.
![Page 32: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/32.jpg)
MySQL
Why normalize? (continued) “A normalized design also lends itself to
change.Business Processes rarely remain constant
after the logical design is complete.”
-- Wiorkowski and Kull, DB2 Design & Development Guide
![Page 33: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/33.jpg)
MySQL
Provides a free open source relational database management system
“MySQL is a polarizing piece of software in the applications development community. It has aspects that many developers like: it’s free, it doesn’t take up a whole lot in the way of resources, it’s very quick, and it’s easy to learn compared to packages like Oracle and Sybase.” --Greenspan and Bulger
![Page 34: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/34.jpg)
MySQL
“However, MySQL achieves its speediness by doing without features common in other database[management systems].” --Greenspan and Bulger
MySQL is behind the feature curve version 3 lacks
subselectsreferential integritystored procedures
![Page 35: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/35.jpg)
MySQL
But since it has been designed by programmers it has nice features lacking in other systems e.g. the ability in the monitor to recall
the previous command entered by entering the up-arrow, which is lacking in Oracle’s SQL*PLUS
![Page 36: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/36.jpg)
MySQL
and much information can be obtained from www.mysql.com
book references DuBois, Paul: MySQL Greenspan, Jay and Brad Bulger:
MySQL/PHP Database Applications (disclosure [or shameless plug]…I am tech-editor of the 2nd edition)
Meloni, Julie: PHP Fast and Easy Development
![Page 37: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/37.jpg)
MySQL Pricing
FREE
![Page 38: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/38.jpg)
PHP & MySQL Example
Build a private database for a search engine intended as an illustration of the power
of these toolsSearch the database(code can be licensed under the GNU
GPL)
![Page 39: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/39.jpg)
Example - Build using Spider
<?php /* spider.php version 2.0 copyright 2001-2003 Stratford Technologies, Inc.
This program is released under the GNU General Public License
at http://www.gnu.org/licenses/gpl.txt */
![Page 40: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/40.jpg)
Spider
/* This program accepts a URL as a starting point and builds a
database for later use by a search engine.
it starts by retrieving those URLs on the subjects page and repeating the process for those URLs. As it proceeds recursively, it saves each URL with a unique integer ID and further saves the words on the page in an index to that URL that also maintains the index of the word.
![Page 41: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/41.jpg)
Spider
URL references found in a given web page, and in turn
follows those URLs if fully qualified, to an arbitrary level of depth--
in this example that level is 3. */
![Page 42: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/42.jpg)
Spider
require 'spiderlib.php'; this gets us a small database access
library let us digress a moment:
![Page 43: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/43.jpg)
Spider Library
<?PHP /* spiderlib.php part of spider.php version 2.0 copyright 2001-2003 Stratford Technologies, Inc.
This program is released under the GNU General Public License at http://www.gnu.org/licenses/gpl.txt */
![Page 44: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/44.jpg)
Spider Library
function myconnect() { require_once '../../dbx_pass.php';
(note this keeps my passwords out of view)
mysql_connect("$host","$user","$pass");
mysql_select_db ("$dbname");
}
![Page 45: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/45.jpg)
Spider Library
function myquery($query) {#echo "query: $query<BR>"; $result=mysql_query($query); return ($result);}
![Page 46: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/46.jpg)
Spider Library
function myfetch($result) { if($result)
$row=mysql_fetch_array($result,MYSQL_ASSOC); return ($row);}
?>
![Page 47: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/47.jpg)
back to Spider.php
// Here is a function to check to ensure a destination is worth reviewing -- this function could be expanded to filter more
function valid(&$dest) { $good=eregi('(http://)',$dest); return ($good);}
![Page 48: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/48.jpg)
Spider.php
// This function allows printing of desired output when debugging
function debug_echo ($output) { // echo "$output"; // this can be
uncommented to allow debug output to print
}
![Page 49: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/49.jpg)
Spider.php
function spider($dest,$count,$parent_dest="") {
// This is the main program, the spider() function. It hunts for
// http:// references in the document that it is handed as $dest,
// and in turn calls itself when it finds any so that it can follow
// a reference chain for $count links.
![Page 50: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/50.jpg)
Spider.php
See code for exact logic and further comments of the spider function.
Note that the function is recursive, calling itself but decrementing a count so that when the count reaches zero it no longer calls itself Recursive functions have to have ways of
stopping themselves from nesting too far// Writes HTML
![Page 51: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/51.jpg)
Spider.php
myconnect(); // uses the library for a standard
connect to the database
![Page 52: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/52.jpg)
Spider.php
echo "<html><body><form method=post name=my_form>"; // simple web page display HTML
![Page 53: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/53.jpg)
Spider.php
$supplied_url = $_POST['supplied_url']; // some configurations of PHP require
this process to obtain POSTed data
![Page 54: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/54.jpg)
Spider.php
if ($supplied_url) { echo "checking
$supplied_url<BR><BR>"; spider($supplied_url,3);}
![Page 55: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/55.jpg)
Spider.php
if (!isset($_POST['supplied_url'])) $supplied_url = 'http://'; // set the value received from previous screen
![Page 56: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/56.jpg)
Spider.php
echo "<BR><BR>Enter URL to check <input type=text size=50 name=supplied_url value='$supplied_url'>";
![Page 57: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/57.jpg)
Spider.php
echo "<BR>…<input type=submit>"; // submit button
echo "</form></body></html>"; // close the HTML
?>
![Page 58: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/58.jpg)
Search.php
<?PHP
/* search.php version 2.0 copyright 2003 Stratford Technologies, Inc.
This program is released under the GNU General Public License at http://www.gnu.org/licenses/gpl.txt
![Page 59: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/59.jpg)
Search.php
It is designed to provide a window into the searchable Web database generated by spider.php.
![Page 60: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/60.jpg)
Search.php
It gives the user the opportunity to enter search terms in a style suitable for the MySQL MATCH() function.
*/
![Page 61: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/61.jpg)
Search.php
Two variables needed from input: $match_phrase=$_POST['match_phrase'
]; $in_boolean=$_POST['in_boolean'];
![Page 62: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/62.jpg)
Search.php
require 'spiderlib.php';
echo "<HTML><BODY><FORM method=post action=$PHP_SELF>";
![Page 63: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/63.jpg)
Search.php
if (isset($match_phrase)) { $match_phrase =
strip_tags($match_phrase); // keep people from crossing you up
myconnect(); // standard connect
![Page 64: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/64.jpg)
Search.php
echo "<table border=1><tr><th width=5%>score</th><th width=30%>url</th><th>found matches to \"$match_phrase\"</th></tr>";
$result=myquery("select *, match (url, webtext) against ('$match_phrase') as score
from SPIweb where match (url, webtext)
against ('$match_phrase') order by score desc");
![Page 65: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/65.jpg)
Search.php
if ($result) while ($row=myfetch($result)) {
$found_string=substr(strip_tags($row[webtext]),0,100); if (strlen($row[webtext])>100)
$found_string .= '...'; $score=number_format($row[score],3); echo "<tr><td
width=5%>$score</td><td width=30%><a href='$row[url]'>$row[url]</td>
<td>$found_string</td></tr>"; }
![Page 66: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/66.jpg)
Search.php
echo "</table>";
}
![Page 67: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/67.jpg)
Search.php
echo "Enter a match phrase <input type='text' name='match_phrase' value='$match_phrase'><BR>
<input type=submit></FORM></BODY></HTML>";
?>
![Page 68: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/68.jpg)
Demonstration
![Page 69: PHP: Hypertext Processor INTEGRATING with MySQL Stratford Technologies, Inc. by Bill Patterson PHP is an open source object oriented scripting/programming.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649de45503460f94adbbe0/html5/thumbnails/69.jpg)
In conclusion
PHP and MySQL constitute a powerful set of tools for dynamic Web site building.
The ability to work with strings in a generic way and to use relational database power to strengthen your Web site enable more applications more easily.
--Bill [email protected]