Re: PEAR DB Oracle 8i problem
| From: | Justin Patrin | Date: | Fri, 30 Jul 2004 17:18:03 +0000 |
| Subject: | Re: PEAR DB Oracle 8i problem | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13919@lists.php.net to get a copy of this message | ||
On Fri, 30 Jul 2004 09:31:33 -0700, Moffet, Scott <smoffet@linkpoint.com> wrote:
> Linux RH 9.0
> PEAR 1.3.2
> DB 1.6.5
> PHP 4.3.8 (compiled with both 'with-Oracle' and 'with-Oci8')
> Oracle 8i
>
> In connecting to a networked Oracle 8i database, PHP's method 'ocilogon' seems
> to work just fine.
>
> I'm trying to move app over to use PEAR::DB, but I'm having trouble connecting.
> (I've googled on this problem for two days before I come to this list)
>
> This works in PHP (without PEAR) just fine:
> _______________________________
>
> $db = "(DESCRIPTION =
> (ADDRESS_LIST =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 123.456.78.90)(PORT = 1521))
> )
> (CONNECT_DATA =
> (SERVICE_NAME = CLEAR)
> )
> )";
>
> $con = ocilogon("login", "password",$db);
>
> #success....
> _______________________________
>
> but I can't get the correct connect string using PEAR
> I'm trying something about like this:
>
> require_once 'DB.php';
> ;
> ;
> $db = "(DESCRIPTION =
> (ADDRESS_LIST =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 123.456.78.90)(PORT = 1521))
> )
> (CONNECT_DATA =
> (SERVICE_NAME = CLEAR)
> )
> )";
>
> $user = 'abc';
> $pass = 'xyz';
> $host = '192.168.40.33:1521';
>
> $dsn = "oci8://$user:$pass@$host/$db";
>
> $db = DB::connect($dsn);
> _______________________________
>
> I've tried many many variations on all the above values.
>
> but this error always comes back:
>
> [nativecode=ORA-12514: TNS:listener could not resolve SERVICE_NAME given in connect
> descriptor] ** oci8://....
>
> So what am I doing wrong in my connection???
> HELP
>
It's a lovely pickle, I know. I proposed a change to oci8.php for DB,
but it was rejected as that string can change all the time....oh well.
Anyway, that should be in the $host portion, not the $db portion. That
*should* fix it.
To get around this, I added my own DB driver which does this for me:
File Edit Options Buffers Tools PHP C Help
<?php
require_once('DB/oci8.php');
/**
* Extends DB_oci8::connect to create a friendly DSN
*/
class DB_oci8ext extends DB_oci8 {
function connect($dsninfo, $persistent = false) {
if($dsninfo['hostspec'] || $dsninfo['database'] ||
$dsninfo['port']) {
$dsninfo['hostspec'] = '(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=
(COMMUNITY = tcp_comm.world)
(PROTOCOL = TCP)
(Host = '.$dsninfo['hostspec'].')
(Port = '.($dsninfo['port'] ? $dsninfo['port'] :
'1521').')
)
)
(CONNECT_DATA =
(SID = '.$dsninfo['database'].')
(GLOBAL_NAME = '.$dsninfo['database'].'.world)
)
)';
}
return DB_oci8::connect($dsninfo, $persistent);
}
}
?>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--