oracle + php ¾Æ·¡¿Í °°ÀÌ µ¥¸óÀ» ±¸µ¿ÇÏ´Ï ÀߵǴõ±º¿ä.
¿ì¼± apache+oracle °¡µ¿ ÁßÁö½ÃÅ°½Ã°í¿ä.
¿À¶óŬ ¼³Ä¡ À¯Àú·Î Á¢¼ÓÇÏ¿©
# svrmgrl DB ¸¶¿îµå ½ÃÅ°°Å
SVRMGR> connect internal
SVRMGR> startup
# lsnrctl start ¸®½º³Ê ±¸µ¿
# /home/www/bin/apachectl start ¾ÆÆÄÄ¡ ½ÃÀÛ
apache À» ÈÄ¿¡ ±¸µ¿ÇØÁÖ¼¼¿ë
Å×ÀÌºí »ý¼ºÀ» À§ÇØ ±âº» »ý¼º °èÁ¤À¸·Î Á¢¼Ó.(Å×½ºÆ®À» À§ÇѺκÐ)
# sqlplus scott/tiger
SQL> CREATE TABLE Çлý(
Çйø NUMBER(4) PRIMARY KEY,
À̸§ CHAR(10),
Çгâ CHAR(1),
Çаú CHAR(8)
);
CREATE TABLE °ú¸ñ(
°ú¸ñ¹øÈ£ CHAR(5) PRIMARY KEY,
°ú¸ñÀ̸§ CHAR(10) not null,
ÇÐÁ¡ number(1),
Çаú CHAR(8),
´ã´ç±³¼ö CHAR(10)
);
CREATE TABLE µî·Ï(
Çйø NUMBER(4),
°ú¸ñ¹øÈ£ CHAR(5),
¼ºÀû CHAR(4),
Áß°£¼ºÀû NUMBER(3),
±â¸»¼ºÀû NUMBER(3),
FOREIGN KEY(Çйø) REFERENCES Çлý(Çйø),
FOREIGN KEY(°ú¸ñ¹øÈ£) REFERENCES °ú¸ñ(°ú¸ñ¹øÈ£)
);
insert into Çлý VALUES (100, '³ª¿¬¹¬', 4, 'ÄÄÇ»ÅÍ');
insert into Çлý VALUES (200, 'ÀÌÂù¿µ', 3, 'Àü±â');
insert into Çлý VALUES (300, 'Á¤±âÅÂ', 1, 'ÄÄÇ»ÅÍ');
insert into Çлý VALUES (400, '¼Ûº´È£', 4, 'ÄÄÇ»ÅÍ');
insert into Çлý VALUES (500, '¹ÚÁ¾È', 2, '»ê°ø');
insert into °ú¸ñ VALUES ('c123', 'ÇÁ·Î±×·¥', 3, 'ÄÄÇ»ÅÍ', '±è¼º±â');
insert into °ú¸ñ VALUES ('c312', 'ÀڷᱸÁ¶', 3, 'ÄÄÇ»ÅÍ', 'Ȳ¼öÂù');
insert into °ú¸ñ VALUES ('c324', 'ÈÀÏó¸®', 3, 'ÄÄÇ»ÅÍ', 'À̱Ôö');
insert into °ú¸ñ VALUES ('c413', 'DB', 3, 'ÄÄÇ»ÅÍ', 'À̼ºÈ£');
insert into °ú¸ñ VALUES ('e412', '¹ÝµµÃ¼', 3, 'ÀüÀÚ°ú', 'È«ºÀÈñ');
insert into µî·Ï VALUES (100, 'c413', 'a', 90, 95);
insert into µî·Ï VALUES (100, 'e412', 'a', 95, 95);
insert into µî·Ï VALUES (200, 'c123', 'b', 85, 80);
insert into µî·Ï VALUES (300, 'c312', 'a', 90, 95);
insert into µî·Ï VALUES (300, 'c324', 'c', 75, 75);
insert into µî·Ï VALUES (300, 'c413', 'a', 95, 90);
insert into µî·Ï VALUES (400, 'c312', 'a', 90, 95);
insert into µî·Ï VALUES (400, 'c324', 'a', 95, 90);
insert into µî·Ï VALUES (400, 'c413', 'b', 80, 85);
insert into µî·Ï VALUES (400, 'e412', 'c', 65, 75);
insert into µî·Ï VALUES (500, 'c312', 'b', 85, 80);
SQL> quit
#######################Å×ÀÌºí »ý¼º ¿Ï·á#####################
# cat > oratest.php (ÀÌ ¼Ò½º¿¡¼ csoracle ºÎºÐÀº ¾Æ·¡ ¼³¸íÇÕ´Ï´Ù.)
oracle db ¿¡ Á¢¼ÓÇÏ¿© select * from Çлý °á°ú¸¦ ±Ü¾î¿À´Â ¿¹Á¦ÀÔ´Ï´Ù.
(¼Ò½º Ãâó´Â Àß ¸ô°Ù³×¿ä.)
<?
//include "./db.inc";
//include "./oracle.inc";
$conn = ora_logon("scott@csoracle","tiger");
$cursor = ora_open($conn);
$sqlstmt = "select * from Çлý";
ora_parse($cursor, $sqlstmt);
ora_exec($cursor);
ora_do($conn, $sqlstmt);
$ncols = ora_numcols($cursor);
$nrows = ora_numrows($cursor);
echo $sqlstmt."<p>";
printf("Result size is $ncols cols by $nrows rows.<br>");
for ($i=0; $i<$ncols; $i++) {
printf("col[%s] = %s type[%d] = %s<br>",$i, ora_columnname($cursor, $i), $i, ora_columntype($cursor, $i));
}
ora_logoff($conn);
?>
############### csoracle ¼³Á¤ºÎºÐ ¼³¸í ##################
¾Æ·¡ ºÎºÐ¿¡¼ csoracle ºÎºÐÀ» Àû¾î ÁØ°Ì´Ï´Ù.(´ë¼Ò¹®ÀÚ ±¸º° ¾ÈÇص˴ϴÙ.)
# cat $¿À¶óŬ¼³Ä¡°æ·Î/network/admin/tnsnames.ora
......
CSORACLE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = csoracle)
)
)
.......
######################################################
ÀÌÁ¦ http://ÁÖ¼Ò/oratest.php Çϼż
select * from Çлý
Result size is 4 cols by 0 rows.
col[0] = Çйø type[0] = NUMBER
col[1] = À̸§ type[1] = CHAR
col[2] = Çгâ type[2] = CHAR
col[3] = Çаú type[3] = CHAR
°¡ ³ª¿À¸é ¼º°ø
Àú ¹Ù»µ¼(-__Á˼Û)
ÂüÁ¶ : http://www.apache.kr.net/documents/dbphp.html
|