0% found this document useful (0 votes)
28 views10 pages

11 20

Uploaded by

BGP BGP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
28 views10 pages

11 20

Uploaded by

BGP BGP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
CHAPTER 1 INTRODUCTION 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, but everything covered in this book also applies to the other editions of the Oracle database, including Oracle Database 11g. The PHP you write for Oracle Database 10g Express Edition can be run, without change, against all editions of the Oracle database as well. The book contains much unique material on PHP's Oracle OCI8 and PDO_OCI extensions. It also incorporates several updated installation guides previously published on the Oracle ‘Technology Network web site. The chapter on globalization is derived from the Oracle Database Express Edition 2 Day Plus PHP Developer Guide, Sue Harper contributed the chapter on SQL Developer. The chapter on PHP Scalability and High Availability is derived from the Oracle whitepaper, PHP Scalability and High Availability, April 2008. We gratefully acknowledge all the Oracle staff that contributed to this book, Who Should Read This Book? This book is aimed at PHP programmers who are developing applications for an Oracle database. It bridges the gap between the many PHP and the many Oracle books available. It shows how to use the PHP scripting language with the Oracle database, from installation to using them together efficiently. You may already be using another database and have a requirement or a preference to move to Oracle. You may be starting out with PHP database development. You may be unsure how to install PHP and Oracle. You may be unclear about best practices. This book aims to remove any confusion. This book is not a complete PHP syntax or Oracle SQL guide. It does not describe overall application architecture. It is assumed that you already have basic PHP and SQI knowledge and want best practices in using PHP against an Oracle database. Since the first release of the Underground PHP and Oracle Manual there have been many commercially available books specifically on PHP and Oracle published. They are worthwhile additions to your library. Each has a different viewpoint and shows something new about the technologies. Oracle's own extensive set of documentation is freely available online. For newcomers we suggest reading the Oracle Database Express Edition 2 Day Plus PHP Developer Guide which walks through building a PHP application against an Oracle database. Comprehensive PHP documentation and resources are also online. URLs to the most useful online resources and books are listed in the Resources appendix. Introduction to Oracle The Oracle Database is well known for its scalability, reliability and features. It is the leading database and is available on many platforms. Introduction There are some subtle differences between the terminology used when describing an Oracle database and a database from other software vendors. The following overview of the main Oracle terms might help you to understand the Oracle terminology. Check the Glossary for more descriptions. Databases and Instances An Oracle database stores and retrieves data. Each database consists of one or more data files. An Oracle database server consists of an Oracle database and an Oracle instance. Every time a server is started, a shared memory region called the system global area (SGA) is allocated and the Oracle background processes are started. The combination of the background processes and SGA is called an Oracle instance. On some operating systems, like Windows, there are no separate background processes. Instead threads run within the Oracle image. Tablespaces Tablespaces are the logical units of data storage made up of one or more datafiles. Tablespaces are often created for individual applications because tablespaces can be conveniently managed. Users are assigned a default tablespace that holds all the data the users creates. A database is made up of default and DBA- created tablespaces, ‘Schemas and Users A schema is a collection of database objects such as tables and indexes. A schema is owned by a database user and has the same name as that user. Many people use the words schema and user interchangeably. Once you have installed PHP and want to write scripts that interact with Oracle, you need to connect as the owner of the schema that contains the objects you want to interact with. For example, to connect to the HR schema, you would use the username hr in PHP's connection string, Although you may have more than one database per machine, typically a single Oracle database contains multiple schemas. Multiple applications can use the same database without any conflict by using different schemas. Instead of using a CREATE DATABASE command for new applications, use the CREATE USSR command to create a new schema in the database. In Oracle Database 10g Express Edition (known as “Oracle Database XE”) there is a wizard to create new users in the Oracle Application Express management console. Introduction to PHP PHP is a hugely popular, interpreted scripting language commonly used for web applications. PHP is open source and free, and has a BSD-style license, making it corporation-friendly. PHP is perfect for rapidly developing applications both big and small, and is great for creating Web 2.0 applications. It powers over twenty million web sites on the Internet and has a huge user community behind it. It runs on many platforms. The language is dynamically typed and easy to use. PHP comes with many extensions offering all kinds of functionality such as database access. PHP 5 introduced strong object orientated capabilities. Introduction to PHP PHP is typically installed as an Apache module, or run by the web server using FastCGI. It includes the PHP OCI8 extension and is linked with the Oracle Client Libraries, enabling Oracle Database access. When auser enters the URL of a PHP script he1 0. php (see step 1 in Figure 1) in their browser, Apache invokes PHP to processes the file. The PHP code is executed (2), with calls to the database (3). Finally, the HTML output is returned to the user's browser (4), which formats and displays the page. http://.../nello.php

hello

London gee helo php
sydney
hello

" query_cities(); > User Web Server Database Figure 1: The four stages of processing a PHP script. ‘The PHP command line interface (CLD) can also be used to run PHP scripts from an operating system shell window. Introduction CHAPTER 2 Gettinc Starteo With PHP This Chapter gives you a very brief overview of the PHP language. Basic PHP syntax is simple to learn. It has familiar loops, tests and assignment constructs. Creating and Editing PHP Scripts There are a number of specialized PHP editors available, including Oracle's JDeveloper which can be configured with a PHP extension. Many developers still prefer text editors, or editors with modes that highlight code syntax and aid development. This manual does not assume any particular editor or debugger is being used PHP scripts often have the file extension .php, but sometimes ptm or .inc are also used. The web server can be configured to recognize the extension(s) that you choose. PHP Syntax Overview PHP scripts are enclosed in tags. Lines are terminated with a semi-colon: "; echo "Full Results"; echo '"7 $output = "no results available";
The output when running this script is:

Fall Results

19> Getting Started With PHP
no results available
A browser would display it as: Full Results [no results available Figure 2: PHP script output. PHP strings can be enclosed in single or double quotes: ", string constant’ “another constant" Variable names are prefixed with a dollar sign. Things that look like variables inside a double-quoted string, will be expanded: "A value appears here: Svi" Strings and variables can also be concatenated using a period. ‘mnployee " . Senane . "is in department ' . sdept Variables do not need types declared: Seount Sename ay varnie'y Arrays can have numeric or associative indexes: Sal (1) = 3.1415 Sa2['Pr') = 3.141 Strings and variables can be displayed with an echo or print statement. Formatted output with print () is also possible. echo ‘Hello, World! '; echo Sv, $x; print ‘Hello, World!'; printf ("there is td $s", $vl, $v2); Code flow can be controlled with tests and loops. PHP also has a switch statement. The ‘ 900000) { echo 'Salary is way too big'; } elseif ($sal > 500000) { echo 'Salary is huge else { echo ‘Salary might be OK"; PHP Syntax Overvie : This also shows how blocks of code are enclosed in braces. A traditional loop is: for (Si = 0; $i < 10; 4484) { echo $i. "
\n" } This prints the numbers 0 to 9, each on a new line. The value of $i is incremented in each iteration. The loop stops when the test condition evaluates to true. You can also loop with while or do while constructs. The foreach command is useful to iterate over arrays: $a3 = array('Aa’, 'Bb', 'Cc'); fereach ($a3 as $v) { echo Sv } This sets Sv to each element of the array in turn, A function may be defined: function myfunc($p1, $p2) { echo $pl, $p27 return $pl + $p2; } Functions may have variable numbers of arguments. This function could be called using: $v3 = myfune(1, 3)7 Function calls may appear earlier than the function definition. Procedures use the same function keyword but do not have a return statement. Sub-files can be included in PHP scripts with an inciude () or requize () statement. include ("£00.php") 7 require (*bar.php' Avequire () will generate a fatal error if the script is not found. The include_once () and reguire_once () statements prevent multiple inclusions of a file. ‘Comments are either single line: 7 a short comment or multi-line: we A longer comment ” Getting Started With PHP Running PHP Scripts PHP scripts can be loaded in a browser, or executed at a command prompt in a terminal window. Because browsers interpret HTML. tags and compress white space including new-lines, script output can differ between command-line and browser invocation of the same script. Many aspects of PHP are controlled by settings in the php.ini configuration file. The location of the file is system specific. Its location, the list of extensions loaded, and the value of all the initialization settings can be found using the php into () function: float (3.1415) } The formatting is apparent when using command-line PHP. In a browser, to prevent white space and new lines coalescing, you will need to do: echo "
$a2['PI') = 3.1415;
var_dump ($22);
echo "
"; Some examples in this manual use var_dunp () to simplify the code being demonstrated or to show the type and contents of a variable. Getting Started With PHP

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy