PHP+Oracle: could not resolve service name

This is a discussion on PHP+Oracle: could not resolve service name within the PHP Language forums, part of the PHP Programming Forums category; I'm developing a PHP 4 application in a Windows Server 2003 box. I'm connecting to a remote Oracle ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008
Álvaro G. Vicario
 
Posts: n/a
Default PHP+Oracle: could not resolve service name

I'm developing a PHP 4 application in a Windows Server 2003 box. I'm
connecting to a remote Oracle 10g server using ODBC (with a system-wide
DSN). I didn't install any of the software and my Oracle experience doesn't
got further than writing queries ;-)

My issue is that PHP scripts cannot connect to the database server when I
run them from the *command line*. I get this error message:

SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:no
se ha podido resolver el nombre del servicio, SQL state 08001 in SQLConnect

Which translates into English as "could not resolve service name".

The *very same code* runs fine when parsed through the web server (Apache2 +
PHP module running as LocalSystem) and I've found no problems using TOAD.
Apart from environment, PHP configuration is identical in command line and
web.

After some Googling I've tried setting TNS_ADMIN and ORACLE_HOME
environmental variables but it didn't make any difference. I just can't
understand why all programs can connect except command line PHP. Do you have
any clue?

Sample code:

<?php

define('DB_DSN', 'FOO');
define('DB_USERNAME', 'FOO');
define('DB_PASSWORD', 'FOO');

odbc_connect(DB_DSN, DB_USERNAME, DB_PASSWORD);

?>


Reply With Quote
  #2 (permalink)  
Old 04-09-2008
Shakespeare
 
Posts: n/a
Default Re: PHP+Oracle: could not resolve service name


"Álvaro G. Vicario" <alvaro_NOSPAM@demogracia.com> schreef in bericht
news:fti9n3$v56$1@huron.algomas.org...
> I'm developing a PHP 4 application in a Windows Server 2003 box. I'm
> connecting to a remote Oracle 10g server using ODBC (with a system-wide
> DSN). I didn't install any of the software and my Oracle experience
> doesn't got further than writing queries ;-)
>
> My issue is that PHP scripts cannot connect to the database server when I
> run them from the *command line*. I get this error message:
>
> SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:no
> se ha podido resolver el nombre del servicio, SQL state 08001 in
> SQLConnect
>
> Which translates into English as "could not resolve service name".
>
> The *very same code* runs fine when parsed through the web server (Apache2
> + PHP module running as LocalSystem) and I've found no problems using
> TOAD. Apart from environment, PHP configuration is identical in command
> line and web.
>
> After some Googling I've tried setting TNS_ADMIN and ORACLE_HOME
> environmental variables but it didn't make any difference. I just can't
> understand why all programs can connect except command line PHP. Do you
> have any clue?
>
> Sample code:
>
> <?php
>
> define('DB_DSN', 'FOO');
> define('DB_USERNAME', 'FOO');
> define('DB_PASSWORD', 'FOO');
>
> odbc_connect(DB_DSN, DB_USERNAME, DB_PASSWORD);
>
> ?>
>


What did you set TNS_ADMIN to? Where is your TNSNAMES.ORA?

Shakespeare


Reply With Quote
  #3 (permalink)  
Old 04-09-2008
Michael Austin
 
Posts: n/a
Default Re: PHP+Oracle: could not resolve service name

Álvaro G. Vicario wrote:
> I'm developing a PHP 4 application in a Windows Server 2003 box. I'm
> connecting to a remote Oracle 10g server using ODBC (with a system-wide
> DSN). I didn't install any of the software and my Oracle experience doesn't
> got further than writing queries ;-)
>
> My issue is that PHP scripts cannot connect to the database server when I
> run them from the *command line*. I get this error message:
>
> SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:no
> se ha podido resolver el nombre del servicio, SQL state 08001 in SQLConnect
>
> Which translates into English as "could not resolve service name".
>
> The *very same code* runs fine when parsed through the web server (Apache2 +
> PHP module running as LocalSystem) and I've found no problems using TOAD.
> Apart from environment, PHP configuration is identical in command line and
> web.
>
> After some Googling I've tried setting TNS_ADMIN and ORACLE_HOME
> environmental variables but it didn't make any difference. I just can't
> understand why all programs can connect except command line PHP. Do you have
> any clue?
>
> Sample code:
>
> <?php
>
> define('DB_DSN', 'FOO');
> define('DB_USERNAME', 'FOO');
> define('DB_PASSWORD', 'FOO');
>
> odbc_connect(DB_DSN, DB_USERNAME, DB_PASSWORD);
>
> ?>
>
>



you still need to add an entry in your tnsnames.ora file (generally
located in the oracle home under network\admin.

A google search will give you many examples of how to create a tnsnames
entry.
Reply With Quote
  #4 (permalink)  
Old 04-09-2008
joel garry
 
Posts: n/a
Default Re: PHP+Oracle: could not resolve service name

On Apr 9, 4:35*am, "Álvaro G. Vicario" <alvaro_NOS...@demogracia.com>
wrote:
> I'm developing a PHP 4 application in a Windows Server 2003 box. I'm
> connecting to a remote Oracle 10g server using ODBC (with a system-wide
> DSN). I didn't install any of the software and my Oracle experience doesn't
> got further than writing queries ;-)
>
> My issue is that PHP scripts cannot connect to the database server when I
> run them from the *command line*. I get this error message:
>
> * * SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:no
> se ha podido resolver el nombre del servicio, SQL state 08001 in SQLConnect
>


Try http://www.oracle.com/technology/pub...p_instant.html

jg
--
@home.com is bogus.
Oops! http://www.computerworld.com.au/index.php/id;314715708
Reply With Quote
  #5 (permalink)  
Old 04-10-2008
Álvaro G. Vicario
 
Posts: n/a
Default Re: PHP+Oracle: could not resolve service name

Álvaro G. Vicario escribió:
> I'm developing a PHP 4 application in a Windows Server 2003 box. I'm
> connecting to a remote Oracle 10g server using ODBC (with a system-wide
> DSN). I didn't install any of the software and my Oracle experience doesn't
> got further than writing queries ;-)
>
> My issue is that PHP scripts cannot connect to the database server when I
> run them from the *command line*. I get this error message:
>
> SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:no
> se ha podido resolver el nombre del servicio, SQL state 08001 in SQLConnect
>
> Which translates into English as "could not resolve service name".
>
> The *very same code* runs fine when parsed through the web server (Apache2 +
> PHP module running as LocalSystem) and I've found no problems using TOAD.
> Apart from environment, PHP configuration is identical in command line and
> web.


I've gathered some more info using Systernal's Filemon utility. It seems
that phpcli.exe does ask Windows about my TNSNAMES.ORA file; Windows
replies that the file exists. But PHP does not even try to read it. It
only reads the following file:

C:\ORANT\ISUITES\net80\admin\sqlnet.ora

AUTOMATIC_IPC = OFF
TRACE_LEVEL_CLIENT = OFF
names.directory_path = (TNSNAMES)
# names.default_domain = world
# name.default_zone = world

The only files it searches and is not found is:

C:\ORANT\ISUITES\net80\names\sdns.ora

There isn't a sdns.ora file anywhere on disk.

When I run the same script through mod_php then Apache.exe opens *and
reads* TNSNAMES.ORA :-?
Reply With Quote
  #6 (permalink)  
Old 04-10-2008
Álvaro G. Vicario
 
Posts: n/a
Default [SOLVED] Re: PHP+Oracle: could not resolve service name

Álvaro G. Vicario escribió:
> My issue is that PHP scripts cannot connect to the database server when I
> run them from the *command line*. I get this error message:
>
> SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:no
> se ha podido resolver el nombre del servicio, SQL state 08001 in SQLConnect
>
> Which translates into English as "could not resolve service name".
>
> The *very same code* runs fine when parsed through the web server (Apache2 +
> PHP module running as LocalSystem) and I've found no problems using TOAD.
> Apart from environment, PHP configuration is identical in command line and
> web.


Oh my... I've fixed it. I had to strip Windows line feeds out of
"TNSNAMES.ORA" and "SQLNET.ORA" and replace them with Unix ones!

http://www.phpbuilder.com/lists/php-db/2001051/0192.php

GRMFFF@#$%&.......

BTW, is there an easy way to specify my own files for this application?
Now it works, I don't want it broken the day any sysadmin edits the file.
Reply With Quote
  #7 (permalink)  
Old 04-11-2008
Ana C. Dent
 
Posts: n/a
Default Re: [SOLVED] Re: PHP+Oracle: could not resolve service name

"Álvaro G. Vicario" <alvaroNOSPAMTHANKS@demogracia.com> wrote in
news:ftlhco$fkr$1@huron.algomas.org:

> Álvaro G. Vicario escribió:
>> My issue is that PHP scripts cannot connect to the database server
>> when I run them from the *command line*. I get this error message:
>>
>> SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154:
>> TNS:no
>> se ha podido resolver el nombre del servicio, SQL state 08001 in
>> SQLConnect
>>
>> Which translates into English as "could not resolve service name".
>>
>> The *very same code* runs fine when parsed through the web server
>> (Apache2 + PHP module running as LocalSystem) and I've found no
>> problems using TOAD. Apart from environment, PHP configuration is
>> identical in command line and web.

>
> Oh my... I've fixed it. I had to strip Windows line feeds out of
> "TNSNAMES.ORA" and "SQLNET.ORA" and replace them with Unix ones!
>
> http://www.phpbuilder.com/lists/php-db/2001051/0192.php
>
> GRMFFF@#$%&.......
>
> BTW, is there an easy way to specify my own files for this
> application? Now it works, I don't want it broken the day any sysadmin
> edits the file.
>


Since I don't do Windoze, this may not work for you.
Under Unix, Oracle will look for .tnsnames.ora (note preceeding dot);
[a.k.a a hidden file in Unix] located in users $HOME directory &
use it if the file exists.

Alternatively which does work for both OS is to define environmental
variable TNS_ADMIN to point to a directory where tnsnames.ora resides.

HTH & YMMV
Reply With Quote
  #8 (permalink)  
Old 04-11-2008
Shakespeare
 
Posts: n/a
Default Re: [SOLVED] Re: PHP+Oracle: could not resolve service name


"Ana C. Dent" <anacedent@hotmail.com> schreef in bericht
news:2mBLj.30954$6J3.8137@newsfe13.phx...
> "Álvaro G. Vicario" <alvaroNOSPAMTHANKS@demogracia.com> wrote in
> news:ftlhco$fkr$1@huron.algomas.org:
>
>> Álvaro G. Vicario escribió:
>>> My issue is that PHP scripts cannot connect to the database server
>>> when I run them from the *command line*. I get this error message:
>>>
>>> SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154:
>>> TNS:no
>>> se ha podido resolver el nombre del servicio, SQL state 08001 in
>>> SQLConnect
>>>
>>> Which translates into English as "could not resolve service name".
>>>
>>> The *very same code* runs fine when parsed through the web server
>>> (Apache2 + PHP module running as LocalSystem) and I've found no
>>> problems using TOAD. Apart from environment, PHP configuration is
>>> identical in command line and web.

>>
>> Oh my... I've fixed it. I had to strip Windows line feeds out of
>> "TNSNAMES.ORA" and "SQLNET.ORA" and replace them with Unix ones!
>>
>> http://www.phpbuilder.com/lists/php-db/2001051/0192.php
>>
>> GRMFFF@#$%&.......
>>
>> BTW, is there an easy way to specify my own files for this
>> application? Now it works, I don't want it broken the day any sysadmin
>> edits the file.
>>

>
> Since I don't do Windoze, this may not work for you.
> Under Unix, Oracle will look for .tnsnames.ora (note preceeding dot);
> [a.k.a a hidden file in Unix] located in users $HOME directory &
> use it if the file exists.
>
> Alternatively which does work for both OS is to define environmental
> variable TNS_ADMIN to point to a directory where tnsnames.ora resides.
>
> HTH & YMMV


In Windows, the TNSNAMES.ORA in de working directory (start in..) will be
used first.

Shakespeare


Reply With Quote
  #9 (permalink)  
Old 04-11-2008
Álvaro G. Vicario
 
Posts: n/a
Default Re: [SOLVED] Re: PHP+Oracle: could not resolve service name

Shakespeare escribió:
>>> BTW, is there an easy way to specify my own files for this
>>> application? Now it works, I don't want it broken the day any sysadmin
>>> edits the file.

[...]
> In Windows, the TNSNAMES.ORA in de working directory (start in..) will be
> used first.



That's right. I've been playing around with current directory and
TNS_ADMIN but of course I got no results because the issue was with the
line endings.

Thank you all for your time.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:49 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0