php ile oracle veritabanı bağlantı scriptleri kodları

Spread the love

Oracle Database Connection Strings in PHP
By Alison Holloway on Apr 20, 2006

It’s easy to get confused as to how to specificy your Oracle database connection string,
and there’s a handy new feature in Oracle 10g
that makes this a whole lot easier. So here’s a little rundown of the three ways to connect to Oracle databases. You can use the:

•tnsnames.ora file
•Full connection string
•Easy connect string
These examples show how to specificy an Oracle connection string using the new OCI8 functions in PHP.

tnsnames.ora File
The tnsnames.ora file is a client side
file that maps an alias used by client programs to a database service. It is used to connect to a non-default database. Here you have to have an entry in the tnsnames.ora file, and
reference the alias to that entry in your connection code.

PHP code:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
oci_connect($un, $pw, 'MYDB');
 
tnsnames.ora entry
 
MYDB = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)
(HOST = mymachine.mydomain)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = MYDB.AU.ORACLE.COM)) )
 
Full Connection String
The full connection string does not require the use of a tnsnames.ora file.
You need to enter the full connection string when you connect to the database in your code.
 
PHP code:
 
oci_connect($un, $pw,
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mymachine.mydomain)(PORT=1521))
(CONNECT_DATA=(SERVER=DEDICATED)
(SERVICE_NAME = MYDB)))');

 

Easy Connect String
This is one Oracle 10g feature that I use daily. As I constantly connect to so many different databases in my day, this has saved me so much time as I don’t have to configure anything, just know the machine name and the database alias and I’m off.

The easy connect string does not require the use of a tnsnames.ora file, and is an abbreviated version of the full connection string. you must have the Oracle 10g client-side libraries to use the easy connect string.

PHP code:

oci_connect($un, $pw, ‘//mymachine.mydomain:port/MYDB’);

Related Posts Plugin for WordPress, Blogger...
PHP kategorisine gönderildi Etiketler:
0 comments on “php ile oracle veritabanı bağlantı scriptleri kodları
1 Sinyaller/Geri izlemeler için "php ile oracle veritabanı bağlantı scriptleri kodları"
  1. […] U knw say orac 2011-11-19 01:10:11 · Reply · View TwitterDoodle by The Chocolate Truth JJ_D: @meldh I guess if Orac was actually going to destroy your house, she'd have managed to do it …1:06:03 · Reply · View tiastone6610: Fruits and vegetables with deep, dark hues pack […]

Bir Cevap Yazın

Login with your Social Account

Son Yazılar