PHP Oracle


Published on

Seminar Sehari
PHP Indonesia
Saturday, 5th May 2012

Pelajari lebih lanjut tentang PHP+Oracle di

Related Content:

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

PHP Oracle

  1. 1. PHP IndonesiaSaturday, 5th May 2102Presented by:Nur Hidayat
  2. 2.  Sehari-hari sebagai Software Developer diESQ LeadershipCenter Di waktu luang mencoba mencari segenggamberlian untuk istri dan anak-anak
  3. 3.  Introduction to Oracle PHP Oracle Extensions InstalasiOracle Database XE Zend ServerVirtualBox Appliance Oracle DatabaseAdministration Interacting with Oracle Database XE Programming PHP+Oracle
  4. 4.  1977,Larry Ellison founded Software Development Laboratories (SDL) Changed name in 1979 to Relational Software Inc. (RSI), 1979 created the first commercial SQL-based relational database. Changed name in 1983 to Oracle Corporation. 1983,Oracle 3 the first relational database to run on mainframes,minicomputers, and PCs 1988, PL/SQL, the first built-in procedural language with very highinfluence from C andAda. 1992,Oracle7, released in 1992, introduced PL/SQL stored proceduresand triggers. 1995, the first to 64-bit database. 1999, the database with XML support 2001,Oracle Real ApplicationClusters (Oracle RAC) 2003, enterprise grid computing environment. In late 2005, released its first full-featured, 100 percent free databaseserver, Oracle Database XE. 2007,Oracle 11g, improved Manageability, diagnosability, and availabilitySee Also: o4730-090772.html for an article summarizing the evolution of Oracle Database
  5. 5.  Express Edition Includes all feature available in Enterprise Edition Limited to single CPU Limited to 1 GB or RAM Limited to 4 GB (10g) or 11 GB (11g) of data Very simple installation Personal Edition Includes all feature available in Enterprise Edition Limited to 1 user
  6. 6.  Standard Edition One Limited to 2 CPU Minus Oracle RAC Standard Edition Limited to 4 CPU Support Oracle RAC Enterprise Edition No CPU Limitation Advanced High Availability (FlashbackTable,Flashback Database, Data Guard, etc.)
  7. 7.  TimesTen, in memory database Berkeley DB, embedded database MySQL, leading free open source database Application Server, web server whichintegrate seamlessly with oracle database E-Business Suite PeopleSoft JD Edwards .... and many more
  8. 8.  Oracle Extension,This extension was designed for Oracle 7 andshould be avoided since it uses a deprecated version of the OracleAPI that will not be available in future releases. ODBC within Windows, while ODBC provides some connectionpooling and other built-in features, it lacks access to many ofOracle’s capabilities such as the ability to store large objects(LOBs). OCI8 Extension, this extension supports most of Oracle’s OracleCall Interface (OCI). PDO Extension.This portable databaseAPI makes it easy tochange your database without changing a lot of your code. Database Abstraction Libraries ADOdb PEAR DB PEAR MDB2
  9. 9.  PilihanWeb Server XAMPP Zend Server InstalasiOracle XE diWindows
  10. 10.  Import ZendAppliance toVirtualBox Username: root Password: zend1234 Konfigurasi Zend Server http://localhost:10081/ KonfigurasiOracle Database XE /etc/init.d/oracle-xe configure
  11. 11.  Starting and Stopping Oracle Database Database and Instance Oracle Storage Structure Oracle Memory Structure Schemas and Users
  12. 12.  Listener The database listener is an Oracle Net program thatlistens for and responds to requests to the database. Database The database is another process that runs inmemory, and needs to be started beforeOracle Netcan handle connection requests to it. Requirements, user must included in dba group on Linux, or ORA_DBA on Windows
  13. 13.  On Linux Starting▪ From Gnome: Select Applications > Oracle Database 10gExpress Edition > Start Database.▪ From KDE: Select K Menu > Oracle Database 10g ExpressEdition > Start Database.▪ From linux shell: # /etc/init.d/oracle-xe restart Stopping▪ From Gnome: Select Applications > Oracle Database 10gExpress Edition > Stop Database.▪ From KDE: Select K Menu > Oracle Database 10g ExpressEdition > Stop Database.▪ From linux shell: # /etc/init.d/oracle-xe stop
  14. 14.  OnWindows Starting▪ From Menu: Start > Oracle Database 10g Express Edition > Start Database.▪ From Control Panel: Start > Settings > Control Panel > Administrative Tools >Services, and select the OracleXETNSListener service. Right click on the Listenerservice, and select Start.▪ From Control Panel: Start > Settings > Control Panel > Administrative Tools >Services, and select the OracleServiceXE service. Right click on the Listenerservice, and select Start. Stopping▪ From Menu: Start > Oracle Database 10g Express Edition > Stop Database.▪ From Control Panel: Start > Settings > Control Panel > Administrative Tools >Services, and select the OracleXETNSListener service. Right click on the Listenerservice, and select Stop.▪ From Control Panel: Start > Settings > Control Panel > Administrative Tools >Services, and select the OracleServiceXE service. Right click on the Listenerservice, and select Stop.
  15. 15.  An Oracle database serverconsists of a database and atleast one database instance Database A database is a set of files,located on disk, that storedata.These files can existindependently of a databaseinstance. Database instance An instance is a set ofmemory structures thatmanage database files.Theinstance consists of a sharedmemory area, called thesystem global area (SGA),and a set of backgroundprocesses.An instance canexist independently ofdatabase files.
  16. 16.  Physical Storage Structures Data files▪ Every Oracle database has one or more physical datafiles, which contain all the database data. Control files▪ Every Oracle database has a control file. Metadataspecifying the physical structure of the database. Online redo log files▪ Every Oracle Database has an online redo log. An onlineredo log is made up of redo entries (also called redorecords), which record all changes made to data.
  17. 17.  Logical Storage Structures Data blocks▪ At the finest level of granularity,Oracle Database data is stored indata blocks. One data block corresponds to a specific number ofbytes on disk. Extents▪ An extent is a specific number of logically contiguous datablocks, obtained in a single allocation, used to store a specific typeof information. Segments▪ A segment is a set of extents allocated for a user object (forexample, a table or index), undo data, or temporary data. Tablespaces▪ A database is divided into logical storage units called tablespaces.A tablespace is the logical container for a segment. Each tablespacecontains at least one data file.
  18. 18.  Client Processes to run the software code of an application program oran Oracle tool. Most environments have separatecomputers for client processes. Server Processes These processes communicate with client processesand interact with Oracle Database to fulfill requests. Background Process Background processes asynchronously perform I/Oand monitor other Oracle Database processes toprovide increased parallelism for better performanceand reliability.
  19. 19.  SystemGlobal Area (SGA) The SGA is a group of shared memory structures thatcontain data and control information for onedatabase instance. Examples of SGA componentsinclude cached data blocks and shared SQL areas. Program Global Areas (PGA) A PGA is a memory region that contain data andcontrol information for a server or backgroundprocess.Access to the PGA is exclusive to the process.Each server process and background process has itsown PGA.
  20. 20.  A database schema is a collection of logicaldata structures, or schema objects. A database schema is owned by a databaseuser and has the same name as the username. Schema objects are user-created structuresthat directly refer to the data in the database. The database supports many types of schemaobjects, the most important of which aretables and indexes.
  21. 21.  Command Line Interface SQL Developer Application Express
  22. 22.  Connecting to Oracle Database Executing SQL Statements Using PL/SQL, Stored Procedure andTriggers Using Oracle LOB DatabaseTransactions
  23. 23.  Use single SQL statement whenever possible If not possible, use PL/SQL or storedprocedure If not possible, use Java or otherprogramming language If still not possible, rethink why you want todo it
  24. 24.  Oracle ConnectionTypes Standard Connections▪ For basic connection to Oracle use PHP’s oci_connect() call:▪ $c = oci_connect($username, $password, $dbname);▪ You can call oci_connect() more than once in a script. If you do this and use thesame username and database name, then you get a pointer to the originalconnection. Multiple Unique Connections▪ To get a totally independent connection use oci_new_connect():▪ $c = oci_new_connect($username, $password, $dbname);▪ Each connection is separate from any other.This lets you have more than onedatabase session open at the same time.This can be useful when you want todo database operations independently from each other. Persistent Connections▪ Persistent connections can be made with oci_pconnect():▪ $c = oci_pconnect($username, $password, $dbname);▪ Persistent connections are not automatically closed at the end of a PHP scriptthis makes oci_pconnect() fast for frequently used web applications.Reconnection does not require re-authentication to the database.
  25. 25.  Oracle Database Name Connection Identifiers The $dbname connection identifier is the name ofthe local or remote database that you want to attachto. Connection Identifiers can be one of: An Easy Connect string A Connect Descriptor string A Connect Name
  26. 26.  An Easy Connect string The Easy Connect string is JDBC-like.The Oracle 10gsyntax is:▪ [//]host_name[:port][/service_name] Using Oracle 11g libraries, the enhanced 11g syntaxcan be used:▪ [//]host_name[:port][/service_name][:server_type][/instance_name]$c = oci_connect(hr, welcome, localhost/XE);$c = oci_connect(scott, ‘tiger,;
  27. 27.  A Connect Descriptor string The full Oracle Net connect descriptor string gives totalflexibility over the connection. The syntax can be more complex than this example,depending on the database and Oracle Net features used. Forexample, by using the full syntax, you can enable features likeload balancing and tweak packet sizes. The Easy Connect syntax does not allow this flexibility.
  28. 28.  A Connect Name A stored Connect Descriptor string In PHP you would use the connect name MYA to connect to thedatabase:▪ $c = oci_connect($username, $password, MYA); PHP needs to be able to find the tnsnames.ora file to resolvethe MYA name.The directory paths that Oracle searches fortnsnames.ora depend on your operating system
  29. 29.  oci_close() The oci_close() function works by referencecounting. Only when all PHP references to thedatabase connection are finished will it actually beclosed and database resources freed. Demo on Close.php
  30. 30.  The possible steps are: Parse: Prepares a statement for execution. Bind: Optionally lets you bind data values, forexample, in theWHERE clause, for betterperformance and security. Define: Optional step allowing you to specify whichPHP variables will hold the results.This is notcommonly used. Execute: The database processes the statement andbuffers any results. Fetch: Gets any query results back from the database.
  31. 31.  Modified FizzBuzz Problem, solved using single SQLstatement
  32. 32.  Sample code usingPL/SQL function togenerate compositefield Function called usingSELECT statement
  33. 33.  Sample code for insertingLOB data into Oracledatabase Sample code for etrievingLOB data from Oracledatabase
  34. 34.  Sample code, increase one salary anddecrease another as a single transaction.
  35. 35.  Oracle and Zend @Zend PHP Developer Center @Oracle Oracle Database XE 11gR2