Database Connection PHP to OracleDB

webstarter7

New member
Hello, i am new here and new to PHP.
I am trying to connect my application with the oracleDB i got provided.
So i have got a TNS entry of the database. Something like this:

Code:
myname =
(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxx.com)(PORT=1530)))
(CONNECT_DATA=(SERVICE_NAME=dbname))
)

and i got provided an jdbc code, like this:
Code:
jdbc:oracle:thin@//xxx-x.xxxxxx.com:1530/myname
.

I never worked with Oracle Database before, so i have no idea. I tried some reserach but only found informations about
Code:
oci_connect
but i think this is not the right for me.

Can u help me to build the connection please.

Thank you mates!
 
on windows you need to find php.ini file and find that line:
Code:
;extension=php_pdo_oci.dll
and remove the semicolon
on linux try to run:
Code:
sudo apt-get install php php-dev php-pear php-cli libaio1
sudo pecl install pdo
after changes you need to restart php-fpm or http server (like apache2)
 
Well, you need to use below connection code for database connections from PHP to OracleDB.

<?php
// Oracle database connection settings
$db_user = 'your_username';
$db_password = 'your_password';
$db_tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxxxx.com)(PORT = 1530))
)
(CONNECT_DATA =
(SERVICE_NAME = dbname)
)
)
";

// Establish a connection to Oracle
$conn = oci_connect($db_user, $db_password, $db_tns);

if (!$conn) {
$error = oci_error();
echo "Connection failed: " . $error['message'];
} else {
echo "Connected to Oracle database!";
// Use the $conn variable to perform database operations
}

// Close the connection when done
oci_close($conn);
?>


Thanks
 
Tôi đã sử dụng dịch vụ vận chuyển quốc tế của Nhật Minh Express và rất hài lòng. Họ đã đảm bảo giao hàng đúng hẹn và hàng hóa của tôi được vận chuyển một cách an toàn hotline: 0937 603 702.
 
Back
Top