Build Your Own Database Driven WebsiteUsing PHP and MySQL(First 4 Chapters)Thank you for downloading the first four chapters of KevinYank’s Build Your Own Database Driven Website Using PHP andMySQL.This excerpt encapsulates the Summary of Contents, Informationabout the Author and SitePoint, Table of Contents, Introduction,and the first four chapters of the book.We hope you find this information useful in evaluating the book.For more information, visit sitepoint.com
Summary of Contents of this ExcerptIntroduction . 11. Installation . 72. Getting Started with MySQL . 353. Getting Started with PHP . 494. Publishing MySQL Data on the Web . 69Summary of Additional Book Contents5. Relational Database Design. 856. A Content Management System . 997. Content Formatting and Submission . 1218. MySQL Administration . 1379. Advanced SQL . 15310. Advanced PHP . 16911. Storing Binary Data in MySQL . 18512. Cookies and Sessions in PHP. 197A. MySQL Syntax . 211B. MySQL Functions . 233C. MySQL Column Types . 251D. PHP Functions for Working with MySQL . 261Index. 273
Build Your Own DatabaseDriven Website using PHP &MySQLby Kevin Yank
Build Your Own Database Driven Website using PHP & MySQLby Kevin YankCopyright ' 2003 SitePoint Pty. Ltd.Editor: Georgina LaidlawCover Design: Julian CarrollPrinting History:First Edition: August 2001Second Edition: February 2003Notice of RightsAll rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmittedin any form or by any means, without the prior written permission of the publisher, except in thecase of brief quotations embodied in critical articles or reviews.Notice of LiabilityThe author and publisher have made every effort to ensure the accuracy of the information herein.However, the information contained in this book is sold without warranty, either express or implied.Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors will be held liable for anydamages to be caused either directly or indirectly by the instructions contained in this book, or bythe software or hardware products described herein.Trademark NoticeRather than indicating every occurrence of a trademarked name as such, this book uses the namesonly in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark.Published by SitePoint Pty. Ltd.Suite 6, 50 Regent Street RichmondVIC Australia 3121.Web: www.sitepoint.comE-Mail: business@sitepoint.comISBN 0-9579218-1-0Printed and bound in the United States of America
About the AuthorKevin Yank is the Technical Business Director for SitePoint, author of numerouswell received tutorials and articles, and editor of the SitePoint Tech Times, an extremely popular technically-oriented newsletter for Web developers.Before graduating from McGill University in Montreal with a Bachelor of Computer Engineering, Kevin was not only a budding Web developer himself, butalso an active advisor for the Sausage Software Web Development Forums, andwriter of several practical guides on advanced HTML and JavaScript.These days, when he's not discovering new technologies, writing books, orcatching up on sleep, Kevin can be found helping other up-and-coming Web developers in the SitePoint Forums.About SitePointSitePoint is a modern day publisher with a particular focus on Web development.Publishing activities are focused around three main areas:sitepoint.com: Online resource for Web designers and developers.SitePoint Books: Printed books available directly through sitepoint.com.SitePoint Email Newsletters: Enlightening editorials, articles, reviews, and casestudies.A big part of SitePoint is the Community Forums, located at sitepointforums.com.Frequented by tens of thousands of Web developers, SitePoint Forums serve asa central discussion hub for Web professionals worldwide.Visit SitePoint at http://www.sitepoint.com/.
To my parents, Cheryl and Richard,for making all this possible.
ii
Table of ContentsIntroduction .Who Should Read This Book .What's In This Book .The Book's Web Site .The Code Archive .Updates and Errata .The SitePoint Forums .The SitePoint Tech Times .Your Feedback .1225555661. Installation . 7Welcome to the Show . 7Windows Installation . 8Installing MySQL . 8Installing PHP . 11Linux Installation . 16Installing MySQL . 17Installing PHP . 21Mac OS X Installation . 24Installing MySQL . 24Installing PHP . 26Mac OS X and Unix . 27Post-Installation Setup Tasks . 27If Your Web Host Provides PHP and MySQL . 29Your First PHP Script . 30Summary . 322. Getting Started with MySQL .An Introduction to Databases .Logging On to MySQL .So what's SQL? .Creating a Database .Creating a Table .Inserting Data into a Table .Viewing Stored Data .Modifying Stored Data .Deleting Stored Data .Summary .3535374040414344464747
Build Your Own Database Driven Website using PHP & MySQL3. Getting Started with PHP .Introducing PHP .Basic Syntax and Commands .Variables and Operators .Arrays .User Interaction and Forms .Control Structures .Multipurpose Pages .Summary .4949515254555963674. Publishing MySQL Data on the Web .A Look Back at First Principles .Connecting to MySQL with PHP .Sending SQL Queries with PHP .Handling SELECT Result Sets .Inserting Data into the Database .A Challenge .Summary .“Homework” Solution .6969717374778080805. Relational Database Design . 85Giving Credit where Credit is Due . 85Rule of Thumb: Keep Things Separate . 87Dealing with Multiple Tables . 89Simple Data Relationships . 93Many-to-Many Relationships . 95Summary . 986. A Content Management System . 99The Front Page . 100Managing Authors . 102Deleting Authors . 103Adding Authors . 104Editing Authors . 105Magic Quotes . 107Managing Categories . 108Managing Jokes . 109Searching for Jokes . 109Adding Jokes . 113Editing and Deleting Jokes . 119Summary . 119iv
Build Your Own Database Driven Website using PHP & MySQL7. Content Formatting and Submission . 121Out with the Old . 122Regular Expressions . 123String Replacement with Regular Expressions . 126Boldface and Italic Text . 126Paragraphs . 127Hyperlinks . 128Matching Tags . 130Splitting Text into Pages . 131Putting it all Together . 133Automatic Content Submission . 135Summary . 1368. MySQL Administration .Backing up MySQL Databases .Standard Backups Aren't Enough .Database Backups using mysqldump .Incremental Backups using Update Logs .MySQL Access Control .Using GRANT .Using REVOKE .Access Control Tips .Locked Out? .Checking and Repairing MySQL Data Files .Summary .1371381381391401421431451461481491529. Advanced SQL . 153Sorting SELECT Query Results . 153Setting LIMITs . 155LOCKing TABLES . 156Column and Table Name Aliases . 158GROUPing SELECT Results . 161LEFT JOINs . 163Limiting Results with HAVING . 165Summary . 16610. Advanced PHP .Server-Side Includes with PHP .Increasing Security with Includes .Semi-Dynamic Pages .Handling File Uploads .Assigning Unique File Names .Recording Uploaded Files in the Database .169170171173177180181v
Build Your Own Database Driven Website using PHP & MySQLEmail in PHP . 182Summary . 18411. Storing Binary Data in MySQL .Binary Column Types .Storing Files .Viewing Stored Files .The Complete Script .Advanced Considerations .MySQL Packet Size .PHP Script Timeout .Summary .18518618718819119519519519612. Cookies and Sessions in PHP . 197Cookies . 197PHP Sessions . 201A Simple Shopping Cart . 204Summary . 209A. MySQL Syntax . 211ALTER TABLE . 211ANALYZE TABLE . 214CREATE DATABASE . 214CREATE INDEX . 214CREATE TABLE . 215DELETE . 217DESCRIBE . 217DROP DATABASE . 217DROP INDEX . 217DROP TABLE . 218EXPLAIN . 218GRANT . 218INSERT . 219LOAD DATA INFILE . 220LOCK/UNLOCK TABLES . 221OPTIMIZE TABLE . 221RENAME TABLE . 222REPLACE . 222REVOKE . 223SELECT . 223Joins . 227SET . 228SHOW . 229vi
Build Your Own Database Driven Website using PHP & MySQLUPDATE . 231USE .
Using PHP and MySQL (First 4 Chapters) Thank you for downloading the first four chapters of Kevin Yank’s Build Your Own Database Driven Website Using PHP and MySQL. This excerpt encapsulates the Summary of Contents, Information about the Author and SitePoint, Table of Contents, Introduction, and the first four chapters of the book.
Database Applications and SQL 12 The DBMS 15 The Database 16 Personal Versus Enterprise-Class Database Systems 18 What Is Microsoft Access? 18 What Is an Enterprise-Class Database System? 19 Database Design 21 Database Design from Existing Data 21 Database Design for New Systems Development 23 Database Redesign 23
Getting Started with Database Classic Cloud Service. About Oracle Database Classic Cloud Service1-1. About Database Classic Cloud Service Database Deployments1-2. Oracle Database Software Release1-3. Oracle Database Software Edition1-3. Oracle Database Type1-4. Computing Power1-5. Database Storage1-5. Automatic Backup Configuration1-6
budget. Using your own customer database as a targeted marketing channel, you can scale down your paid advertising as you build your own database and your WiFi marketing ROI increases. Likewise, as you begin improving your revenue by bringing in more business using your low-cost customer database, your overall cost per acquisition will begin to
The term database is correctly applied to the data and their supporting data structures, and not to the database management system. The database along with DBMS is collectively called Database System. A Cloud Database is a database that typically runs on a Cloud Computing platform, such as Windows Azure, Amazon EC2, GoGrid and Rackspace.
Creating a new database To create a new database, choose File New Database from the menu bar, or click the arrow next to the New icon on the Standard toolbar and select Database from the drop-down menu. Both methods open the Database Wizard. On the first page of the Database Wizard, select Create a new database and then click Next. The second page has two questions.
real world about which data is stored in a database. Database Management System (DBMS): A collection of programs to facilitate the creation and maintenance of a database. Database System DBMS Database A database system contains information about a particular enterprise. A database system provides an environment that is both
of the New database wizard deals with the setup of the relational database. 6. In the New database wizard page, check Use existing (since the database has already been created in the DBMS; see3) and press Next . 7. In the Locate database wizard page, press the Build button to create a connection to the relational database.
Unlimited One-on-one Spanish Tutoring for 149 a Month. In all, we spent over a thousand hours building this. I literally can not think of a single thing about it that could be better, and I’m a perfectionist. When everyone else wanted to release the blueprint back when it was 95% of the way there, I held it back until I couldn’t find a single thing we could improve. If you're looking to .