Connect PHP with Oracle [closed]

0

I'm trying to connect PHP (WAMP) with Oracle but I get the following error:

  

Call to undefined function ora_logon ()

Code I'm using:

$db = "(description =
(address =
 (protocol = tcp)
 (host = www.servidor.com.br) //link omitido
 (port = 1521)) (connect_data = (service_name = www.servidor.com.br) //link omitido
)
)";
// Conexão com Oracle usando OCI
$c = ora_logon('[email protected]', 'fabrica');
    
asked by anonymous 25.04.2015 / 17:36

2 answers

1

The function ora_logon was a function used in PHP4 , we do not use it anymore, now we use oci_login , for example, that allows access to 12c, 11g , 10g, 9i and 8i.

  • Edit the file php.ini and remove the semicolon from the following line (if it is windows)

    extension=php_oci8_11g.dll
    

    If it is * nix:

    extension=oci8.so
    
  • Windows:

  • Download the OTN Instant Client page - probably 32bit , but if it fails and your php is 64bit, maybe you should try it.
  • Extract the downloaded file into C:\instantclient_11_2
  • Add the path to the System Variables ( PATH ) Start Menu > Control Panel > System and Security > System > Advanced system settings (or type in the run / cmd SystemPropertiesAdvanced )
  • Look for the button called Environment Variables
  • You have two areas, User Variables and System Variables , look in System Variables for the PATH variable and click edit
  • Add this to the end (be careful not to delete what you already have) ;C:\instantclient_11_2
  • The function used to connect used is oci_login , documentation function list link

    p>

    Example usage:

    <?php
    $conn = oci_connect('hr', 'welcome', 'localhost/XE');
    if (!$conn) {
        $e = oci_error();
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }
    
    $stid = oci_parse($conn, 'SELECT department_id, department_name FROM departments');
    oci_execute($stid);
    
    while (($row = oci_fetch_assoc($stid)) != false) {
        echo $row['DEPARTMENT_ID'] . " " . $row['DEPARTMENT_NAME'] . "<br>\n";
    }
    
    oci_free_statement($stid);
    oci_close($conn);
    
        
    26.06.2015 / 17:48
    0

    If you have not yet found a solution, see the following:
    - Uncomment or extension = php_oci8.dll extension = php_oci8_11g.dll extension = php_pdo_oci.dll in php.ini
    - Install client 11g, administrator mode
    - Copy the TNS Names to the C: \ oracle \ product \ 10.2.0 \ client_1 \ NETWORK \ ADMIN
    folder - Add in the environment variable the path Client and PHP.

    With these steps my applications here work normally.

        
    26.06.2015 / 16:32