The Underground PHP and Oracle Manual

This book is designed to bridge the gap between the many PHP and the many Oracle texts available. It shows how to use the PHP scripting language with the Oracle database, from installation to using them efficiently. The installation and database discussion in this book highlights the Oracle Database 10g Express Edition,…

More PDF Content

The Underground PHP and Oracle Manual
Chapter 1 Introduction…1
Who Should Read This Book?…1 Introduction to Oracle…1 Databases and Instances…2 Tablespaces…2 Schemas and Users…2 Introduction to PHP…2

Chapter 2 Getting Started With PHP…5
Creating and Editing PHP Scripts…5 PHP Syntax Overview…5 Running PHP Scripts…8 Running PHP Scripts in a Browser…8 Running Scripts with Command Line PHP…8 Debugging PHP Scripts…8

Chapter 3 PHP Oracle Extensions…11
PHP Oracle Extensions…11 Oracle Extension…11 OCI8 Extension…11 PDO Extension…12 PHP Database Abstraction Libraries…13 ADOdb…13 PEAR DB…14 PEAR MDB2…14 Getting the OCI8 Extension…14 OCI8 and Oracle Installation Options…15 Getting the PDO Extension…16 Zend Core for Oracle…17 The PHP Release Cycle…17

Chapter 4 Installing Oracle Database 10g Express Edition…19
Oracle Database Editions…19 Oracle Database XE…19 Installing Oracle Database XE on Linux…20 Installing Oracle Database XE on Debian, Ubuntu, and Kubuntu…21 Installing Oracle Database XE on Windows…22 Testing the Oracle Database XE Installation…24 Configuring Oracle Database XE…25 Setting the Oracle Database XE Environment Variables on Linux…25

Enabling Database Startup and Shutdown from Menus on Linux…26 Starting and Stopping the Listener and Database…26 Enabling Remote Client Connection…29

Chapter 5 Using Oracle Database…31
Oracle Application Express…31 Logging In To Oracle Application Express…31 Unlocking the HR User…32 Creating Database Objects…33 Working with SQL Scripts…37 Creating a PL/SQL Procedure…38 Creating a Database User…40 Monitoring Database Sessions…42 Database Backup and Recovery…44 Oracle SQL*Plus…47 Starting SQL*Plus…48 Executing SQL and PL/SQL Statements in SQL*Plus…49 Controlling Query Output in SQL*Plus…49 Running Scripts in SQL*Plus…50 Information On Tables in SQL*Plus…50 Accessing the Demonstration Tables in SQL*Plus…51 Oracle SQL Developer…51 Creating a Database Connection…51 Creating a Table…54 Executing a SQL Query…55 Editing, Compiling and Running PL/SQL…57 Running Reports…59 Creating Reports…61

Chapter 6 Installing Apache HTTP Server…63
Installing Apache HTTP Server on Linux…63 Starting and Stopping Apache HTTP Server…64 Configuring Apache HTTP Server on Linux…64 Installing Apache HTTP Server on Windows…64 Starting and Stopping Apache HTTP Server…65

Chapter 7 Installing PHP…67
Installing PHP with OCI8 on Linux…67 Installing OCI8 Using a Local Database…67 Installing OCI8 Using Oracle Instant Client…69 Upgrading PHP with PECL OCI8 on Linux…70 Upgrading OCI8 as a Static Library on Linux …70 Upgrading OCI8 on Linux Using the PECL Channel…71 Upgrading OCI8 as a Shared Library on Linux…72

Installing PHP With OCI8 on Windows…73 Installing OCI8 Using a Local Database on Windows…73 Installing OCI8 with Instant Client on Windows…74 Upgrading OCI8 on Windows…75 Installing OCI8 with Oracle Application Server on Linux…76 Installing PHP With PDO…78 Installing PDO on Linux…79 Installing PDO on Windows…80 Checking OCI8 and PDO_OCI Installation…80

Chapter 8 Installing Zend Core for Oracle…83
Installing Zend Core for Oracle…83 Installing Zend Core for Oracle on Linux…83 Testing the Zend Core for Oracle Installation on Linux…89 Installing Zend Core for Oracle on Windows…90 Testing the Zend Core for Oracle Installation on Windows…97 Configuring Zend Core for Oracle…97

Chapter 9 Connecting to Oracle Using OCI8…101
Oracle Connection Types…101 Standard Connections…101 Multiple Unique Connections…101 Persistent Connections…101 Oracle Database Name Connection Identifiers…102 Easy Connect String…103 Database Connect Descriptor String…104 Database Connect Name…104 Common Connection Errors…105 Setting Oracle Environment Variables for Apache…106 Closing Oracle Connections…108 Close Statement Resources Before Closing Connections…109 Transactions and Connections…110 Session State with Persistent Connections…110 Optional Connection Parameters…111 Connection Character Set…111 Connection Session Mode…112 Changing the Database Password…114 Changing Passwords On Demand…114 Changing Expired Passwords…115 Tuning Oracle Connections in PHP…117 Use the Best Connection Function…117 Pass the Character Set…117 Do Not Set the Date Format Unnecessarily…117

Managing Persistent Connections…119 Maximum Number of Persistent Connections Allowed…119 Timeout for Unused Persistent Connections…119 Pinging for Closed Persistent Connections…119 Apache Configuration Parameters…120 Reducing Database Server Memory Used By Persistent Connections…120 Oracle Net and PHP…121 Connection Rate Limiting…121 Setting Connection Timeouts…122 Configuring Authentication Methods…122 Detecting Dead PHP Apache Sessions…123 Other Oracle Net Optimizations…123 Tracing Oracle Net…123 Connection Management in Scalable Systems…124

Chapter 10 Executing SQL Statements With OCI8…125
SQL Statement Execution Steps…125 Query Example…125 Oracle Datatypes…127 Fetch Functions…127 Fetching as a Numeric Array…128 Fetching as an Associative Array…129 Fetching as an Object…130 Defining Output Variables…131 Fetching and Working with Numbers…131 Fetching and Working with Dates…132 Insert, Update, Delete, Create and Drop…134 Transactions…134 Autonomous Transactions…136 The Transactional Behavior of Connections…137 PHP Error Handling…138 Handling OCI8 Errors…138 Tuning SQL Statements in PHP Applications…141 Using Bind Variables…141 Tuning the Prefetch Size…149 Tuning the Statement Cache Size…150 Using the Server and Client Query Result Caches…151 Limiting Rows and Creating Paged Datasets…153 Auto-Increment Columns…155 Getting the Last Insert ID…157 Exploring Oracle…157 Case Insensitive Queries…157

Analytic Functions in SQL…158

Chapter 11 Using PL/SQL With OCI8…159
PL/SQL Overview…159 Blocks, Procedures, Packages and Triggers…160 Anonymous Blocks…160 Stored or Standalone Procedures and Functions…160 Packages…161 Triggers…162 Creating PL/SQL Stored Procedures in PHP…162 End of Line Terminators in PL/SQL with Windows PHP…162 Calling PL/SQL Code…163 Calling PL/SQL Procedures…163 Calling PL/SQL Functions…164 Binding Parameters to Procedures and Functions…164 Array Binding and PL/SQL Bulk Processing…165 PL/SQL Success With Information Warnings…167 Using REF CURSORS for Result Sets…168 Closing Cursors…170 Converting from REF CURSOR to PIPELINED Results…172 Oracle Collections in PHP…173 Using PL/SQL and SQL Object Types in PHP…175 Using OCI8 Collection Functions…176 Using a REF CURSOR…177 Binding an Array…179 Using a PIPELINED Function…180 Getting Output with DBMS_OUTPUT…181 PL/SQL Function Result Cache…183 Using Oracle Locator for Spatial Mapping…184 Inserting Locator Data…184 Queries Returning Scalar Values…184 Selecting Vertices Using SDO_UTIL.GETVERTICES…186 Using a Custom Function…186 Scheduling Background or Long Running Operations…188 Reusing Procedures Written for MOD_PLSQL…191

Chapter 12 Using Large Objects in OCI8…193
Working with LOBs…193 Inserting and Updating LOBs…193 Fetching LOBs…194 Temporary LOBs…195 LOBs and PL/SQL procedures…196 Other LOB Methods…197

Working with BFILEs…198

Chapter 13 Using XML with Oracle and PHP…203
Fetching Relational Rows as XML…203 Fetching Rows as Fully Formed XML…204 Using the SimpleXML Extension in PHP…205 Fetching XMLType Columns…206 Inserting into XMLType Columns…207 Fetching an XMLType from a PL/SQL Function…209 XQuery XML Query Language…210 Accessing Data over HTTP with XML DB…212

Chapter 14 PHP Scalability and High Availability…213
Database Resident Connection Pooling…213 How DRCP Works…214 PHP OCI8 Connections and DRCP…216 When to use DRCP…218 Sharing the Server Pool…219 Using DRCP in PHP…220 Configuring and Enabling the Pool…221 Configuring PHP for DRCP…223 Application Deployment for DRCP…224 Monitoring DRCP…226 V$PROCESS and V$SESSION Views…227 DBA_CPOOL_INFO View…227 V$CPOOL_STATS View…227 V$CPOOL_CC_STATS View…229 High Availability with FAN and RAC…229 Configuring FAN Events in the Database…230 Configuring PHP for FAN…230 Application Deployment for FAN…230 RAC Connection Load Balancing with PHP…231

Chapter 15 Globalization…233
Establishing the Environment Between Oracle and PHP…233 Manipulating Strings…235 Determining the Locale of the User…235 Encoding HTML Pages…236 Specifying the Page Encoding for HTML Pages…236 Specifying the Encoding in the HTTP Header…237 Specifying the Encoding in the HTML Page Header…237 Specifying the Page Encoding in PHP…237 Organizing the Content of HTML Pages for Translation…237 Strings in PHP…238

Static Files…238 Data from the Database…238 Presenting Data Using Conventions Expected by the User…238 Oracle Number Formats…239 Oracle Date Formats…240 Oracle Linguistic Sorts…242 Oracle Error Messages…243

Chapter 16 Testing PHP and the OCI8 Extension…245
Running OCI8 Tests…245 Running a Single Test…247 Tests that Fail…247 Creating OCI8 Tests …248 OCI8 Test Helper Scripts…249 Configuring the Database For Testing…249

Appendix A Tracing OCI8 Internals…253
Enabling OCI8 Debugging output…253

Appendix B OCI8 php.ini Parameters…255 Appendix C OCI8 Function Names in PHP 4 and PHP 5…257 Appendix D The Obsolete Oracle Extension…261
Oracle and OCI8 Comparison…261

Appendix E Resources…267
General Information and Forums…267 Oracle Documentation…267 Selected PHP and Oracle Books…268 Software and Source Code…269 PHP Links…271

Glossary…273

Download The Underground PHP and Oracle Manual pdf from www.oracle.com, 290 pages, 6389.8KB.
Related Books

Leave a Reply