Forum Stats

  • 3,874,324 Users
  • 2,266,719 Discussions
  • 7,911,813 Comments

Discussions

oci_pconnect(): ORA-12541: TNS:no listener (Read details)

3211911
3211911 Member Posts: 1
edited Apr 12, 2016 1:29AM in PHP

I have  created a database for E-voting system on SQL developer Oracle 12c by CREATE_TABLE commands and INSERT_INTO commands for making and inserting data into the tables. In 12c, I had a connection call "Qurat" to the database. I did not use the create database command.

I need to connect it to a webpage using PHP. I've PHP 5.6.19 and WAMP 3.0.0 on Windows10 [Localhost runs smoothly, APACHE is connected, all services running. WAMP is green]

I downloaded the instant client OCI8 for Oracle and did the configuration in PHP.ini file.

Now when I run the following script:<?php

<?php
$c = oci_pconnect("scott", "tiger", "localhost/orcle");
if(!$c) {echo 'Connected';}
else {echo 'failed';}


$result = oci_parse($c, "select fname from NIC where NICno=4250167366706");
if (!$result){
    $err = oci_error();
  echo "Could not parse the oci";
  exit;
  }
  $r = oci_execute($result);
  if (!$r) {
   $error = oci_error($conn);
  echo "Could not execute." . $error['message'];
  exit;
  }
    oci_close();
?>

It gives me the following output which indicates that the connection is successfully done. But there's issue in parsing it.

Warning: oci_pconnect(): ORA-12541: TNS:no listener in C:\wamp\www\Hello\1.php on line 3
Connected
Warning: oci_parse() expects parameter 1 to be resource, boolean given in C:\wamp\www\Hello\1.php on line 7
Could not parse the oci

I have checked the 'Services' , listener.ora file, tnsnames.ora file. I've also tried reloading using lsnrctl and it successfully does that. I have tried almost every solution on the internet.

I have two OracleHomeUser(s) although I use only one of them. I tried deleting the folder for OracleHomeUser1 manually by shift+delete but the deletion process had to skip some files since they are being used somewhere else. Is this problem because of this?
or Am i referring to the database in a wrong way?

This is the output i get from lsnrctl status

Capture.jpg

Gaz in Oz

Answers

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,785 Bronze Crown
    edited Apr 3, 2016 10:10PM

    Hi 3211911,

    Looks like your listener is actually listening on "PORT=1522" from screenshot in output from "lsnrctl status"

    Try changing your oci_pconnect "easy connect" string to include the port number 1522 (as without specifying it, it will default to port 1521):

    $c = oci_pconnect("scott", "tiger", "localhost:1522/orcle");
    if(!$c) {echo 'Connected';}
    else {echo 'failed';}
    
    

    This page may help in understanding connect strings using oci_pconnect()

    PHP: oci_pconnect - Manual

    ...and even though the above error is a "Warning", it basically saying the connection failed. Not sure why your code thinks it "Connected" as oci_pconnect should have returned "FALSE".

    Cheers,

    Gaz.

  • Christopher Jones-Oracle
    Christopher Jones-Oracle Member Posts: 1,656 Employee
    edited Apr 6, 2016 9:51PM

    It says 'Connected' because the condition logic is inverted: if(!$c) should be if($c)

    Gaz in Oz
  • Gaz in Oz
    Gaz in Oz Member Posts: 3,785 Bronze Crown
    edited Apr 12, 2016 1:29AM
This discussion has been closed.