Php 5.22 With Oracle 9i

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Php 5.22 With Oracle 9i

Post by gtcol »

Hello all,
I am trying to connect to Oracle 9i from Php 5.2 on Win2K, IIS 5x. Following is the snippet, gives me blank page with no error msg at all. I have enabled extension=php_oci8.dll in php.ini and restarted IIS and server both. Nothing seems to help. Please advise.

Code: Select all

<?php

    //echo "HELLOW WORLD";
    $db='(DESCRIPTION =
                      (ADDRESS = (PROTOCOL = TCP)(HOST = GT-LAP)(PORT = 1521))
                      (CONNECT_DATA =
                      (SERVICE_NAME = Orcl)
                      )
    )';
    //echo $db;
    $c = oci_connect('SAdm', 'SPas',$db);
    //echo $c;
    $s = oci_parse($c, 'SELECT Orderkey FROM Orders');
    oci_execute($s);
    while ($res = oci_fetch_array($s)) {
    echo $res['ORDERKEY'] . "<br>";
    }
    oci_close($c);

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
	$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

you might want to try zend core

Post by yacahuma »

You may want to try oracle zend core. Its is free and it install all the oracle stuff necessary for php to run. It might be a bit overkill, but if you are in a production environment , I think is worth it.


Also use phpadodb instead of the straight oracle call. The debug mode alone is extremely handy for database stuff.
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Post by gtcol »

Hello all,
here is the output for Feyd's script. Feyd, could you also please explain if your script is enough to check all necessary php.ini settings? As for using PHPADODB, thanx for the advise. I will look into it and then lets see if that is really worth it for small sized projects like ours. :).

PHP Version: 5.2.2
PHP OS: WINNT
Error Reporting: 6143 (E_ALL)
Register Globals: Off
Short Tags: Off
Display Errors: Off
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: C:\WINDOWS\php.ini
Loaded Extensions:
bcmath calendar com_dotnet ctype
session filter ftp hash
iconv json odbc pcre
Reflection date libxml standard
tokenizer zlib SimpleXML dom
SPL wddx xml xmlreader
xmlwriter ISAPI mssql

Thanks once again,
gtcol
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

oci is not loaded, are you sure you edit the correct php.ini which in your installation is C:\WINDOWS\php.ini
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Post by gtcol »

Miro_igov,
No doubtedly, I've uncommented following extensions in Php.ini at C:\Windows\.

extension=php_oci8.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll

Please advise what I am missing here.

Thank you all for your kind suggestions and advices.

gtcol
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please restart the IIS , then run this script

Code: Select all

<?php
$ini = get_cfg_var('cfg_file_path');
echo "<pre>\n";
echo 'ini: ', $ini, "\n";
foreach( file($ini) as $l ) {
	if ( strpos($l, 'oci') ) {
		echo $l;
	}
}
echo "\n</pre>\n";
and post the output.
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Post by gtcol »

V,
Here is the output for your scipt.


ini: C:\WINDOWS\php.ini
extension=php_oci8.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
;oci8.privileged_connect = Off
; ping during oci_pconnect() to check the connection validity. When
; set to 0, each oci_pconnect() will cause a ping. Using -1 disables
;oci8.ping_interval = 60
;oci8.default_prefetch = 10
; Compatibility. Using On means oci_close() will not close
; oci_connect() and oci_new_connect() connections.
;oci8.old_oci_close_semantics = Off

Hope you get what you wanted to see here.

Thanks,
gtcol
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Post by gtcol »

Hi all,
I am still stuck up on the same issue. Please advise. Any clue or hint is highly appreciated.

Thanks,
gtcol
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

enable display_errors in php.ini , restart server and try again.
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Post by gtcol »

Hi Miro_igov,
Now its coming up with following error message. I believe it has to do either with php.ini settings or DB connection string. But its being an extra pain in a** to track the bug out.

Fatal error: Call to undefined function oci_connect() in D:\Gtp\Dms\Cust\h1.php on line 12.

Please advise.

Thanks,
gtcol
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you install the oracle instant client and set LD_LIBRARY_PATH and NLS_LANG as mentioned under "Requirements" at http://de2.php.net/oci ?
gtcol
Forum Newbie
Posts: 20
Joined: Mon May 28, 2007 10:15 am
Contact:

Post by gtcol »

Hi Volka,
I also tried connecting to DB server that I have in the same PC. It is not allowing me to connect to the DB server on the same PC. Do we still need to install Instant client and set those env vars when we already have DB server there?

Thanks,
gtcol
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

As long as you get "Fatal error: Call to undefined function oci_connect()" you should not even worry about where the database is located.. First you need to get the extension loaded.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

FYI, Oracle's official PHP Development Center : http://www.oracle.com/technology/tech/php/index.html
Post Reply