Connection to oracle with php

Discussion in 'PHP' started by joseph44, Apr 19, 2010.

  1. #1
    I am not able to get any help from anywhere I tried it a lot I hope someone from DP will help me.

    Can someone tell me how can I connect oracle and php?
     
    joseph44, Apr 19, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You will have to install the OCI8 extension - there are other ways but this is by far your best bet.

    What host are you running this on? If they do not have support for it already you may find you have trouble setting it up. You can find out if its already enabled by checkiung phpinfo().

    If its your own server or one you have root access too (and its not enabled) you need to recompile it with;

    --with-oci8=shared,instantclient,/path/to/your-instant-client-libs
     
    lukeg32, Apr 19, 2010 IP
  3. frank100

    frank100 Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    a sample code
    
    
    $dbHost = "localhost";                           
        $dbHostPort="1521";                              
        $dbServiceName = "orcl";                        
        $usr = "hr";                                 
        $pswd = "hr";                                
        $dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) 
                  (HOST=".$dbHost.")(PORT=".$dbHostPort.")) 
                      (CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))"; 
        if(!$dbConn = oci_connect($usr,$pswd,$dbConnStr)) {             
           $err = oci_error();                                         
           trigger_error(‘Could not establish a connection: ‘  
                                       . $err[‘message'], E_USER_ERROR); 
        };
        $strSQL = "SELECT TO_CHAR(SYSDATE, ‘HH:MI:SS') ctime FROM DUAL";
        $stmt = oci_parse($dbConn,$strSQL);                             
        if (!oci_execute($stmt)) {                                      
           $err = oci_error($stmt);                                     
           trigger_error(‘Query failed: ‘ . $err[‘message'], E_USER_ERROR); 
        };
        oci_fetch($stmt);                                      
        $rslt = oci_result($stmt, ‘CTIME');                    
        print "<h3>The current time is ".$rslt."</h3>";
    
    Code (markup):
     
    frank100, Apr 19, 2010 IP