LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   PHP Oracle 9i Connection Problem (RH9) (https://www.linuxquestions.org/questions/linux-software-2/php-oracle-9i-connection-problem-rh9-174606/)

dhammika 04-26-2004 01:51 AM

PHP Oracle 9i Connection Problem (RH9)
 
Hello everybody

I config Oracle Server 9i (9.2.0.4.0) on my linux box (2.4.20-8) and try to connect with PHP 4.2.2. (httpd Apache 1.3.22)

Oracle server start and running , test on PHP was O.K. But when try to connect to oracle.

It says

Fatal error:
Call to undefined function:
oci_connect() in /var/www/test/<php_page>.php on line <no>

Any thing wrong. (PHP not support to 9i.)

help me.

linux_pioneer 07-05-2004 09:45 PM

dhammika,

I ran into the same problem but I'm using Fedora which is essentially rh10. I guess the php modules that come w/ redhat don't provide any oracle functions. I had to download the php source code and install with the options:
--with-oci8
--with-apxs2=/usr/local/apache2/bin/apxs(this is assuming that you are using apache2 if not just point to where ever the apxs file is located)

This should work. Now that I've figured that out I'm running into to this other problem. PHP will now recognize the oracle functions but I get this error message:
Warning: ocilogon(): _oci_open_server: ORA-12541: TNS:no listener in /usr/local/apache2/htdocs/oracletest.php on line 6

Maybe you or someone else can figure this one out. Let me know if you were able to get past that 1st issue though.

dhammika 07-06-2004 05:05 AM

Hi linux_pioneer

Yes you are correct , I resolve this problem long time ago and now I am successfully continue my PHP project .

If you can send your code (only the oracle connection part) I think I can help you

Dhammika

linux_pioneer 07-08-2004 02:58 AM

dhammika,

here's my code:

<?php

$logon = OCILogon('sysdba', 'oracle', 'TSH1');
$sqlCMD = 'SELECT * FROM Contacts';
$query = OCIParse($logon, $sqlCMD);
OCIExecute($query);
while(OCIFetch($query)){
for($x=1; $x <= OCINumCols($query); $x++)
echo OCIResult($query, $x);
echo "<br>";
}
OCILogoff($logon);
?>

this is the error I get with this code:
Warning: ocilogon(): _oci_open_server: ORA-12541: TNS:no listener in /usr/local/apache2/htdocs/oracletest.php on line 6

thanks for the help!

dhammika 07-08-2004 05:02 AM

Are you sure you start the listener

[oracle@keg-ora ]$ lsnrctl start

linux_pioneer 07-10-2004 04:20 AM

Okay got past that error but now I get this one:
ocilogon(): _oci_open_server: Error while trying to retrieve text for error ORA-12154

any clue? can you show me a sample of your code?

dhammika 07-11-2004 09:57 PM


did you specify the ORACLE_SID env variable correctly ...



yes. this is the sample code I used as a base. This code from oracle.otn and it is running perfectly try to run it .


<?php

$db_conn = ocilogon( "scott", "tiger" );

$cmdstr = "SELECT * FROM EMP";



$parsed = ociparse($db_conn, $cmdstr);
ociexecute($parsed);



$nrows = ocifetchstatement($parsed, $results);

echo "<html><head><title>Oracle PHP Test</title></head><body>";
echo "<center><h2>Oracle PHP Test</h2><br>";
echo "<table border=1 cellspacing='0' width='50%'>\n<tr>\n";
echo "<td><b>Name</b></td>\n<td><b>Salary</b></td>\n</tr>\n";


for ($i = 0; $i < $nrows; $i++ )
{
echo "<tr>\n";
echo "<td>" . $results["ENAME"][$i] . "</td>";
echo "<td>$ " . number_format($results["SAL"][$i], 2). "</td>";
echo "</tr>\n";

}

echo "<tr><td colspan='2'> Number of Rows: $nrows</td></tr></table>";
echo "<br><em>If you see data, then it works!</em><br></center></body></html>\n";


?>


And the this set of code that use adodb (you can download it) to connect to the ORACLE 9i.




<?php
$UserName = trim($HTTP_POST_VARS['user_id']);
$Address = $HTTP_POST_VARS['address'];
$Name = $HTTP_POST_VARS['name'];
$Email = $HTTP_POST_VARS['email'];


include('adodb/adodb.inc.php');
include('adodb/adodb-errorpear.inc.php');
$server = '192.168.56.3:1521';
$user = 'scott';
$db = ADONewConnection('oci8');

$db->Connect($server, $user, 'tiger', 'keg');

if ($db->Execute("INSERT INTO USERS ( USERID,NAME,ADDRESS,EMAIL) VALUES('$UserName','$Address','$Name','$Email')")==false)
{

echo

'<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="enter_user.php">
<table width="100%" border="0" height="100%">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td bgcolor="#000099">
<div align="center"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<font size="5">';

echo " User id <font color=#ffff00> " . $UserName."</font> is already in use. Press back button and enter a different user id.</font></font></div> ";
echo ' </td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>

';

}

else
{
include "enter_user.php";

}


?>

linux_pioneer 07-12-2004 05:51 AM

got it working. i really appreciate your help. Now i can use oracle instead of mysql (no reason just wanted to try something different). thanks again!

emmbec 03-28-2005 02:18 PM

How did you got it working, I canīt seem to be able to get it right. I have the listener starting perfectly, and the ORACLE_SID variable set correctly. I still get the same error:


Warning: ocilogon(): _oci_open_server: Error while trying to retrieve text for error ORA-12541 in /export/home/cartorpp/WWW/prueba/test.php on line 3
Oracle Connect Error

this is the php file:

<?php
if ($c=OCILogon("user", "password","qro")) {

echo "Successfully connected to Oracle.\n";

OCILogoff($c);

} else {

$err = OCIError();

echo "Oracle Connect Error " . $err[text];

}
?>


All times are GMT -5. The time now is 07:00 AM.