PEAR is the PHP Extension and Application Repository, and is a framework and distribution system for reusable, high-quality PHP components, available in the form of "packages". In this book, you will learn how to use a number of the most powerful PEAR packages to boost your PHP development productivity. By focusing on the packages for key development activities, this book gives you an in-depth guide to getting the most from these powerful coding resources. You will become a master of various PEAR packages that help you with the essential tasks of PHP development: . Accessing databases with MDB2 . Displaying data in a range of formats (HTML, Excel spreadsheet, PDF) . Creating and parsing XML documents . Serializing PHP objects into XML, and unserializing XML documents to PHP objects . Consuming and offering web services . Accessing Web APIs including Google, Yahoo, Amazon, and Technorati" PHP Programming with PEAR 1 Table of Contents 8 Preface 14 Chapter 1: MDB2 18 A Brief History of MDB2 18 Abstraction Layers 19 Database Interface Abstraction 19 SQL Abstraction 19 Datatype Abstraction 20 Speed Considerations 20 MDB2 Package Design 20 Getting Started with MDB2 21 Installing MDB2 21 Connecting to the Database 22 DSN Array 22 DSN String 22 Instantiating an MDB2 object 23 Options 23 Option "persistent" 24 Option "portability" 24 Setting Fetch Mode 25 Disconnecting 25 Using MDB2 25 A Quick Example 26 Executing Queries 27 Fetching Data 27 Shortcuts for Retrieving Data 28 query*() Shortcuts 28 get*() Shortcuts 29 getAssoc() 30 Data Types 31 Setting Data Types 31 Setting Data Types when Fetching Results 32 Setting Data Types for get*() and query*() 33 Quoting Values and Identifiers 33 Iterators 34 Debugging 35 MDB2 SQL Abstraction 36 Sequences 36 Setting Limits 37 Replace Queries 37 Sub-Select Support 38 Prepared Statements 39 Named Parameters 40 Binding Data 40 Execute Multiple 41 Auto Prepare 41 Auto Execute 42 Transactions 43 MDB2 Modules 44 Manager Module 45 Function Module 48 Reverse Module 49 Extending MDB2 50 Custom Debug Handler 51 Custom Fetch Classes 53 Custom Result Classes 54 Custom Iterators 57 Custom Modules 57 Mymodule2 58 MDB2_Schema 59 Installation and Instantiation 59 Dump a Database 59 Switching your RDBMS 62 Summary 63 Chapter 2: Displaying Data 64 HTML Tables 64 Table Format 65 Using HTML_Table to Create a Simple Calendar 66 Setting Individual Cells 67 Extended HTML_Table with HTML_Table_Matrix 69 Excel Spreadsheets 71 The Excel Format 71 Our First Spreadsheet 72 About Cells 73 Setting Up a Page for Printing 73 Adding some Formatting 74 About Colors 75 Pattern Fill 76 Number Formatting 77 Adding Formulas 79 Multiple Worksheets, Borders, and Images 80 Other ways to create Spreadsheets 82 CSV 82 The Content-Type Trick 82 Generating Excel 2003 Files 82 Creating Spreadsheets using PEAR_OpenDocument 83 DataGrids 83 DataSources 84 Renderers 84 A Simple DataGrid 85 Paging the Results 86 Using a DataSource 86 Using a Renderer 87 Making it Pretty 88 Extending DataGrid 89 Adding Columns 90 Generating PDF Files 91 Colors 95 Fonts 95 Cells 96 Creating Headers and Footers 96 Summary 97 Chapter 3: Working with XML 98 PEAR Packages for Working with XML 99 Creating XML Documents 99 Creating a Record Label from Objects 101 Creating XML Documents with XML_Util 105 Additional Features 109 Creating XML Documents with XML_FastCreate 110 Interlude: Overloading in PHP5 111 Back to XML 112 Creating the XML Document 115 Pitfalls in XML_FastCreate 117 Creating XML Documents with XML_Serializer 118 XML_Serializer Options 120 Adding Attributes 122 Treating Indexed Arrays 123 Creating the XML Document from the Object Tree 126 Putting Objects to Sleep 129 What's your Type? 131 Creating Mozilla Applications with XML_XUL 133 XUL Documents 133 Creating XUL Documents with XML_XUL 136 Creating a Tab Box 140 Processing XML Documents 142 Parsing XML with XML_Parser 144 Enter XML_Parser 145 Implementing the Callbacks 146 Adding Logic to the Callbacks 149 Accessing the Configuration Options 152 Avoiding Inheritance 153 Additional XML_Parser Features 155 Processing XML with XML_Unserializer 156 Parsing Attributes 158 Mapping XML to Objects 161 Unserializing the Record Labels 167 Additional Features 169 XML_Parser vs. XML_Unserializer 169 Parsing RSS with XML_RSS 170 Summary 174 Chapter 4: Web Services 176 Consuming Web Services 177 Consuming XML-RPC-Based Web Services 177 Accessing the Google API 183 Consuming REST-Based Web Services 186 Searching Blog Entries with Services_Technorati 186 Accessing the Amazon Web Service 192 Consuming Custom REST Web Services 201 Offering a Web Service 209 Offering XML-RPC-Based Web Services 210 Error Management 215 Offering SOAP-Based Web Services 218 Error Management 223 Offering REST-Based Services using XML_Serializer 225 Our Own REST Service 227 Summary 235 Chapter 5: Working with Dates 236 Working with the Date Package 236 Date 237 Creating a Date Object 237 Querying Information 238 Manipulating Date Objects 239 Comparing Dates 240 Formatted Output 241 Creating a Date_Span Object 242 Manipulating Date_Span Objects 243 Timespan Conversions 244 Comparisons 244 Formatted Output 245 Date Objects and Timespans 245 Dealing with Timezones using Date_Timezone 246 Creating a Date_Timezone object 247 Querying Information about a Timezone 247 Comparing Timezone Objects 248 Date Objects and Timezones 248 Conclusion on the PEAR::Date Package 250 Date_Holidays 250 Instantiating a Driver 251 Identifying Holidays 252 The Date_Holidays_Holiday Class 253 Calculating Holidays 253 Getting Holiday Information 254 Filtering Results 255 Combining Holiday Drivers 257 Is Today a Holiday? 257 Multi-Lingual Translations 259 Adding a Language File 260 Getting Localized Output 261 Conclusion on Date_Holidays 263 Working with the Calendar Package 263 Introduction to Basic Classes and Concepts 265 Object Creation 268 Querying Information 268 Building and Fetching 270 Make a Selection 271 Validating Calendar Date Objects 272 Validation Versus Adjustment 273 Dealing with Validation Errors 273 Adjusting the Standard Classes' Behavior 274 What are Decorators? 275 The Common Decorator Base Class 275 Bundled Decorators 275 Generating Graphical Output 276 Navigable Tabular Calendars 278 Summary 283 Index 284 XML, Data, Dates, Web Services, and Web APIsAbout This BookMaximize your productivity through the use of proven, powerful, reusable PHP componentsIn-depth coverage of a range of important PEAR packagesMany code examples provide a clear and practical guidanceWho This Book Is ForThis book is for PHP developers who want to maximize their productivity through the use of proven, high-quality, reusable PEAR components. Some experience of working with PEAR classes will prove helpful, and developers who've used PEAR before can find something new to delight them.What You Will LearnChapter 1 shows you how to access databases with the MDB2 package. You will learn:Connecting to the database, and instantiate objectsExecuting queries and fetching dataMDB2 SQL abstraction; sequences, replace queries, sub-select support, prepared statementsUsing MDB2 modulesExtending MDB2 to provide custom fetch and result classes, iterators, and modulesChapter 2 explains how to use PEAR packages to display data. It teaches you:Creating powerful tables of data easily with the HTML_Table packageAdvanced table formatting with HTML_Table_MatrixCreating Excel spreadsheets dynamically with Spreadsheet_Excel_WriterAdding formatting to these spreadsheets including colors, patterns, formulae and number formattingCreating flexible, sortable grids of data with Structures_DataGridAdding columns to the grid, control paging, select data sources, and renderersUsing File_PDF to create PDF documents on the flyChapter 3 covers the usage of PEAR packages to work with XML and stresses on:Creating XML documents with XML_Util, XML_FastcreateTransforming PHP objects to XML format with XML_SerializerCreating Mozilla applications with XML_XULParsing XML with XML_ParserProcessing XML documents to PHP objects with XML_UnserializerParsing RSS with XML_RSSChapter 4 is an extensive tutorial on working with web services and Web API's using PEAR packages. We cover the following topics:Consuming web servicesConsuming XML-RPC-based web servicesAccessing the Google APISearching blog entries with Services_TechnoratiAccessing the Amazon web serviceAccessing the Yahoo APIOffering XML-RPC-based web servicesOffering SOAP-based web servicesOffering REST-based services using XML_SerializerChapter 5 covers PEAR's date and time functions using the PEAR::Calendar and PEAR::Date packages such as:Creating, manipulating, and comparing Date objectsData_Span arithmeticHandling timezones with Date_TimezoneKeeping track of public holidays with Date_HolidayUsing the Calendar class to display an HTML calendarIn DetailPEAR is the PHP Extension and Application Repository, and is a framework and distribution system for reusable, high-quality PHP components, available in the form of'packages'.In this book, you will learn how to use a number of the most powerful PEAR packages available to boost your PHP development productivity. By focusing on these packages for key development activities, this book is an in-depth guide to getting the most from these powerful coding resources.Style and approachPacked with code examples, every topic is explained in a clear, practical way.
pear Is The Php Extension And Application Repository, And Is A Framework And Distribution System For Reusable, High-quality Php Components, Available In The Form Of Packages. In This Book, You Will Learn How To Use A Number Of The Most Powerful Pear Packages To Boost Your Php Development Productivity. By Focusing On The Packages For Key Development Activities, This Book Gives You An In-depth Guide To Getting The Most From These Powerful Coding Resources.
you Will Become A Master Of Various Pear Packages That Help You With The Essential Tasks Of Php Development:
. Accessing Databases With Mdb2
. Displaying Data In A Range Of Formats (html, Excel Spreadsheet, Pdf)
. Creating And Parsing Xml Documents
. Serializing Php Objects Into Xml, And Unserializing Xml Documents To Php Objects
. Consuming And Offering Web Services
. Accessing Web Apis Including Google, Yahoo, Amazon, And Technorati
PEAR is the PHP Extension and Application Repository, and is a framework and distribution system for reusable, high-quality PHP components, available in the form of "packages". This book teaches you how to use a number of the most powerful PEAR packages available to boost your PHP development productivity.