Database Articles

  Home arrow Database Articles arrow Getting Information with PHP`s Oracle ...
DATABASE ARTICLES

Getting Information with PHP`s Oracle Functionality
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2011-01-12

    Table of Contents:
  • Getting Information with PHP`s Oracle Functionality
  • Viewing User Tables

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Getting Information with PHP`s Oracle Functionality


    (Page 1 of 2 )

    In this sixth part of a seven-part series on PHP's Oracle functionality, you will learn how to view database characteristics and user tables. This article is excerpted from chapter 32 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

    Viewing Database Characteristics

    As you may remember from Chapter 28, there is a subtle but clear distinction between a database and an instance. The database consists of the files on disk. These files store the data itself, the state of the database in the control file, and changes to the databases data in redo log files. The instance, on the other hand, refers to the Oracle memory processes and memory structures that reside in your server's memory and accesses the database stored in the disk files. For most databases, including Oracle Database XE, there is one and only one instance for each database. For those versions of Oracle Database 10g that support RAC, you can have more than one instance per database.

    To retrieve information about the database, you can query the dynamic performance view V$DATABASE; similarly, you can query the dynamic performance view V$INSTANCE to retrieve information about the instance. Listing 32-10 shows you how to retrieve key informational columns from these two views, and Figure 32-3 shows you the results. We discuss dynamic performance views (views that start with V$) in Chapter 35.

    Listing 32-10. Querying Database and Instance Characteristics (query_db_info.php)

    <?php
       $c = oci_connect('rjb', 'rjb', '//localhost/xe');
       $s = oci_parse($c,'select name, created, log_mode, open_mode from v$database');
       oci_execute($s);
       echo '<b>Database Characteristics:</b><br /><br />';

       $res = oci_fetch_array($s);
       echo 'Database Name: ' . $res['NAME'] . '<br />' ;
       echo 'Created: ' . $res['CREATED'] . '<br />' ;
       echo 'Log Mode: ' . $res['LOG_MODE'] . '<br />' ;
       echo 'Open Mode: ' . $res['OPEN_MODE'] . '<br />' ;

       echo '<br /><br />';
       $s = oci_parse($c,'select instance_name, host_name, version,
                            startup_time, status, edition from v$instance');
       oci_execute($s);
       echo '<b>Instance Characteristics:</b><br /><br />';

       $res = oci_fetch_array($s);
       echo 'Instance Name: ' . $res['INSTANCE_NAME'] . '<br />' ;
       echo 'Host Name: ' . $res['HOST_NAME'] . '<br />' ;
       echo 'Version: ' . $res['VERSION'] . '<br />' ;
       echo 'Startup Time: ' . $res['STARTUP_TIME'] . '<br />' ;
       echo 'Status: ' . $res['STATUS'] . '<br />' ;
       echo 'Edition: ' . $res['EDITION'] . '<br />' ;

       oci_close($c);
    ?>


    Figure 32-3.  Database and instance metadata

    More Database Articles Articles
    More By Apress Publishing

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap