How to connect PHP to Oracle

Asked

Viewed 612 times

-2

What are the most important conditions for a PHP connection to ORACLE?

I already wrote these extensions in PHP.ini and it didn’t work

extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
extension=php_oci8.dll
extension=php_oci8_12c.dll
extension=php_oracle.dll
extension=pdo_odbc
extension=pdo_pgsql

Code used

<?php

$conn="(DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVICE_NAME = PRD)
  (SERVER = DEDICATED)
)//pequei essa parte do TSname
)";
$conexao = oci_connect('DBA', '123', $conn);

if (isset ($conexao) || empty($conexao)){
    $erro = oci_error();
    trigger_error(htmlentities($erro['erro'], ENT_QUOTES), E_USER_ERROR);
exit;
}

echo"ola";

?>

Mistakes

Fatal error: Uncaught Error: Call to undefined function oci_connect() in C:\wamp64\www\Teste\testes\conexaooracle.php on line 12 

Error: Call to undefined function oci_connect() in C:\wamp64\www\Teste\testes\conexaooracle.php on line 12 

2 answers

-2

Try with PDO follows below an example of connection, it was a way I managed to connect with Oracle I’m testing the OCI so I am indicating the PDO.

$conn = new PDO("oci:dbname=dbname;host=localhost", 'user', 'pass');

-3

- Windows 10

- Xampp V3.2.4 and Php 8

- x64

  • Standard installation of Xampp;
  • Installation of the Instantcliente (instantclient-basic-windows.x64-19. 6.0.0.0dbru);
  • I put the Instantcliente in the C: Instanteclient;
  • Add the Instantcliente as an environment variable (Locate the PATH variable and click EDIT and add at the beginning of the value:);
  • I copied All the DLLS of the Folder of Instantclient for: C: xampp php and C: xampp apache bin
  • I downloaded the Package idle of the site: https://pecl.php.net/package/oci8 I used the version 3.0.1 for Windows (php_oci8-3.0.1-8.0-ts-vs16-x64);
  • I copied All Files php_* to the folder C: xampp php ext
  • I edited the php.ini removing the comment ';' from extensio=oci8_11g
  • I saved everything and restarted APACHE;
  • Check whether in the PHPINFO appears idle;

inserir a descrição da imagem aqui

Browser other questions tagged

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