Connect PHP with Oracle

Asked

Viewed 6,568 times

0

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

Call to Undefined Function ora_logon()

Code I am 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');
  • The oracle extension is enabled?

  • You are enabled: extension=php_oci8.dll 
extension=php_oci8_11g.dll 
extension=php_pdo_oci.dll

  • You have the documentation link to ora_logon only found something related to php4. With oci_connect you can make the connection?

2 answers

1

The function ora_logon was a function used in the old days (at the same time) in the PHP4, today we no longer use it, now we use it oci_login for example, which allows access to 12c, 11g, 10g, 9i and 8i.

  1. Edit the file php.ini and remove the point and comma from the following line (if windows)

    extension=php_oci8_11g.dll
    

    If it is *Nix:

    extension=oci8.so
    

Windows:

  1. Download the OTN Instant Client page - probably the 32bit, but if it fails and your php is 64bit, maybe you should try it.
  2. Extract the downloaded file in C:\instantclient_11_2
  3. Add the path to System variables (PATH) Start Menu > Control Panel > System & Security > System > Advanced System Settings (or type in Run/cmd SystemPropertiesAdvanced)
  4. Look for the button called Environment variables
  5. Has two areas, User variables and System variables, search in System variables the variable PATH and click edit
  6. Add this at the end (be careful not to delete what you already have) ;C:\instantclient_11_2

The function used to connect used is oci_login, list of documentation functions http://php.net/manual/en/book.oci8.php

Example of use:

<?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);

0

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

With these steps my applications here work normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.