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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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); ?> |
|
|||
|
"Á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 |
|
|||
|
Á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. |
|
|||
|
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 |
|
|||
|
Á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 :-? |
|
|||
|
Á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. |
|
|||
|
"Á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 |
|
|||
|
"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 |
|
|||
|
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. |