I’m encountering an issue trying to connect to an Oracle database using Visual Studio PHP Server on my Windows . I’ve installed the oci8 extension, and I know it works correctly because PHP doesn’t throw any errors related to the extension and i can see the extension in phpinfo. I tried to connect with this code:
$host = "iacademy2.oracle.com";
$port = "1521";
$service_name = "orclpdb";
$username = "username";
$password = "password";
$dsn = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $host)(PORT = $port))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = $service_name)
)
)";
$conn = oci_connect($username, $password, $dsn);
if (!$conn) {
$e = oci_error();
echo "Connection error: " . $e['message'];
exit;
}
echo "Successfully connected to Oracle!";
However, despite the extension being correctly installed and activated, I am facing issues with the connection. The errors I receive are:
ORA-12170: TNS: Connect timeout occurred
ORA-12541: TNS: No listener
How can I resolve this Oracle database connection issue from PHP, considering that the oci8 extension is already installed and functioning correctly, and I can access the Oracle database in the browser? Do you have any ideas? I would be very grateful. I need this for my faculty.
Additionally, I am able to access the Oracle database through the browser (via https://iacademy2.oracle.com/ords/
), so I know that the Oracle instance is up and running. However, I am having trouble connecting to it through PHP.
I’ve tried modifying the HOST value in the connection string to different addresses, but that didn’t resolve the issue. The connection still fails. I used 192.168.0.1 as host but it says:
Warning: oci_connect(): ORA-12541: TNS:no listener in D:frontendpagestest.php on line 16
Connection error: ORA-12541: TNS:no listener.
I also have the XAMPP turned on. One more thing is that from cmd I tried to use C:\Users\Lenovo>telnet iacademy2.oracle.com 1521
Connecting To iacademy2.oracle.com…Could not open connection to the host, on port 1521: Connect failed