½ÃÀÛÆäÀÌÁö·Î Áñ°Üã±âÃß°¡
·Î±×ÀÎ
ȸ¿ø°¡ÀÔ l Ã⼮üũ l ¸¶ÀÌÆäÀÌÁö l CGIMALL
ÀÚ·á½Ç »çÀÌÆ®µî·Ï ·©Å·100 ÇÁ·Î±×·¥¸®ºä °ü¸®ÀÚÃßõÀÚ·á Ãʺ¸°¡À̵å
Ä¿¹Â´ÏƼ
Àüü ÆîÃ帱â
Äü¸Þ´º¸µÅ© jquery , CSS , PHP , Javascript , ¹«·áÆùÆ® , ASP
»ó¼¼°Ë»ö
Ȩ > Ä¿¹Â´ÏƼ > °ñµåÆÁ »ó¼¼º¸±â
Ä¿¹Â´ÏƼ ±¸Àα¸Á÷
»çÀÌÆ®µî·Ï
Ŭ¶ó¿ìµåű×
Javascript
PHP
asp
CSS
html
mysql
jquery
image
Mobile
API
slide
°Ô½ÃÆÇ
¸Þ´º
ÇöÀçÁ¢¼ÓÀÚ ¸í »õ·Î°íħ
°Ô½ÃÆÇŸÀÌƲ °ñµåÆÁ / »ó¼¼º¸±â
Æ®À§ÅÍ·Î º¸³»±â
Ãßõ¼ö 344 | Á¶È¸¼ö 3,528 | µî·ÏÀÏ 2001-11-27 00:19:02

´Ð³×ÀÓ

HappyCGI

Á¦¸ñ

2. DBI ¿Í ÆÞÀÇ ¿¬°á - µ¥ÀÌŸ ÀԷ¹æ¹ý
³»¿ë
¾È³çÇϼ¼¿ä. ÇØÇÇCGI À¥¸¶½ºÅÍ À±¿µ¿õÀÔ´Ï´Ù.
1³âÀ» ¹Ì·ç´ø Â÷¿¡ °­Á¸¦ ½ÃÀÛÇϳ׿ä.
(1³â¸¸¿¡ ½Ã°£ÀÌ Á» ³ª¼­ -_-v ÄÐ~)

¿¹Àü DBI¿Í ÆÞÀÇ °ü°è¿¡ ´ëÇؼ­ ¼³¸íÀ» µå·È½À´Ï´Ù.
ÀÌÁ¦´Â ¾à°£ ½ÇÀü ¹®Á¦ÀÎ DBI¿Í ÆÞÀÇ ¿¬°á
±×¸®°í °£´ÜÇÑ ¿¹Á¦¸¦ º¾´Ï´Ù.
À̹ø °­Á´ perl¿¡¼­ mysql ¾ÈÀ¸·Î ¾î¶»°Ô °ªÀ» ³Ö´ÂÁö
¾Ë¾Æº¾´Ï´Ù.

¿ì¼± ¾ÕÀ¸·Î °­Á¿¡ ¾µ Å×À̺íÀ» ¸¸µé¾îº¸°Ú½À´Ï´Ù.
¾Æ·¡¸¦ Âü°íÇϼż­ mysql¿¡ ÀÚ½ÅÀÌ »ç¿ëÇÏ´Â DB³»¿¡
¾Æ·¡ Å×À̺íÀ» ¸¸µì´Ï´Ù.
(Áߺ¹ÀÌ µÇÁö ¾Ê°Ô Á¶±Ý µ¶Æ¯ÇÑ Çʵå À̸§À» »ç¿ëÇßÁÒ ^^)

CREATE TABLE happy_hero_okok (
  number int(11) DEFAULT '0' NOT NULL auto_increment,
  name varchar(100) NOT NULL,
  email varchar(100),
  title varchar(200) NOT NULL,
  comment text NOT NULL,
  inquire int(10) DEFAULT '0' NOT NULL,
  date date DEFAULT '0000-00-00' NOT NULL,
  PRIMARY KEY (number)
);



¹æ¸í·ÏÀ» ¿ì¼± ¸¸µé¾î º¼ »ý°¢ÀÌ´Ï±î ¹æ¸í·Ï¿¡ ¸Â°Ô ÃÖ¼ÒÇÑ °£´ÜÈ÷
Å×À̺íÀ» ¸¸µé¾î º¸¾Ò½À´Ï´Ù.
number´Â ÇÁ¶óÀ̸Ӹ®Å°ÀÌ°í ÀÚµ¿Áõ°¡
name À̸§ ÀÔ·ÂÇÒ°÷
email À̸ÞÀÏ ÀÔ·ÂÇÒ°÷
title ¹æ¸í·Ï Á¦¸ñ ÀÔ·ÂÇÒ°÷
comment ¹æ¸í·Ï ³»¿ëÀÔ·ÂÇÒ°÷
inquire Á¶È¸¼ö¸¦ ³ªÅ¸³¾°÷
date ±Û µî·ÏÀÏ ÀúÀåÇÒ°÷.
ÀÌ»óÀÔ´Ï´Ù.

http://www.happycgi.com/lecture/1127test.cgi
À§ ÁÖ¼Ò´Â Å×½ºÆ®ÁÖ¼ÒÀÔ´Ï´Ù.

¾Æ·¡´Â ¼Ò½ºÄÚµåÀÌ°í ¾ÐÃàÆÄÀϷεµ ¹ÞÀ»¼ö ÀÖ½À´Ï´Ù.


#!/usr/bin/perl
#########################################################
use DBI; #DBI¶õ ¸ðµâÀ» »ç¿ëÇÑ´Ù°í ¼±¾ðÇÕ´Ï´Ù.
$database = "yourDBname"; #ÀÚ½ÅÀÇ DB¸í
$hostname = "localhost";  #mysql È£½ºÆ® À§Ä¡
$dsn = "DBI:mysql:database=$database;host=$hostname";
$user = "mysqlid"; #mysql ¾ÆÀ̵ð
$pw = "mysqlpass";  #mysql Æнº¿öµå
$dbh = DBI->connect("$dsn", "$user", "$pw");
$table_name = "happy_hero_okok"; #»ç¿ëÇÒ Å×À̺í¸í
#########################################################
# Àӽ÷Π°ªÀ» ÀÏ´Ü ÁÝ´Ï´Ù.
# ¿À´ÃÀº ÀԷ¸¸ Å×½ºÆ®Çϱ¸¿ä.
#

$name = "Å×½ºÆ®Áß";
$email = 'webmaster@happycgi.com';
$title = "Å×½ºÆ®Á¦¸ñ";
$comment = "³»¿ëÀÔ´Ï´Ù.\n Àߵdzª¿ä?";
$inquire = "0";

print "content-type:text/html\n\n";
# ¾Æ·¡ ±¸¹®Àº °¡Àå ¸¹ÀÌ ¾²´Â ±¸¹®ÀÔ´Ï´Ù.
# do¸¦ Àß ¾È¾²½Ã´Â ºÐµµ ÀÖ´Ù´øµ¥
# Á¦°¡ º¸±â¿£ Á¦ÀÏ ÆíÇÑ°Í °°¾Æ¼­ ¸»ÀÌÁÒ. ^^
# Åë°·Î ±×³É ¿Ü¿ì¼¼¿ä.


$sth = $dbh->do ("insert into $table_name values('','$name','$email','$title','$comment','$inquire',curdate()) ") or die print "$DBI::errstr
DB Á¢¼Ó¿¡·¯";

# $DBI::errstrt ÀÌ ¹«¾ùÀ̳ĸé
# dbh¿¡¼­ ´øÁ®ÁØ ¸í·É¿¡ ¹®Á¦°¡ ÀÖÀ»¶§ ±× ¹®Á¦Á¡À» Ãâ·ÂÇØÁÝ´Ï´Ù.
# or die ¹®Àº ¾Æ½ÃÁÒ. ¾ÈµÇ¸é ½ºÅéÇضó..

print "Àß µî·ÏµÇ¾ú³×¿ä. ^^";

# µî·ÏÀÌ Àß µÇ¾úÀ¸¸é print ¹®À¸·Î °¡¼­ Àß µî·ÏµÇ¾ú´Ù°í Ãâ·ÂÇÏ°ÚÁÒ?



¿À´ÃÀº ¿ä±îÁö ÀÔ´Ï´Ù.
¾ÆÁÖ °£´ÜÇÑ ¼Ò½ºÁÒ?
À¥»ó¿¡ È£ÃâÀ» ÇÏ¸é ¹«Á¶°Ç DB°¡ ÀúÀåµË´Ï´Ù.
(´ç¿¬ÇÏÁö¸¸ ... -_-;;;)
ÀúÀåµÇ¾ú³ª mysql¿¡¼­ Á÷Á¢ È®ÀÎÀ» Çغ¸±¸¿ä.

ƯÈ÷ ¾Æ·¡ ¹®Àå

#!/usr/bin/perl
#########################################################
use DBI; #DBI¶õ ¸ðµâÀ» »ç¿ëÇÑ´Ù°í ¼±¾ðÇÕ´Ï´Ù.
$database = "yourDBname"; #ÀÚ½ÅÀÇ DB¸í
$hostname = "localhost";  #mysql È£½ºÆ® À§Ä¡
$dsn = "DBI:mysql:database=$database;host=$hostname";
$user = "mysqlid"; #mysql ¾ÆÀ̵ð
$pw = "mysqlpass";  #mysql Æнº¿öµå
$dbh = DBI->connect("$dsn", "$user", "$pw");
$table_name = "happy_hero_okok"; #»ç¿ëÇÒ Å×À̺í¸í
#########################################################

Àº ¸Å¹ø ¾²ÀÏ°ÍÀÌ´Ï ÀÚÁÖ º¹»çÇؼ­ ¾µ°Ì´Ï´Ù.
¾Ï±â Çϼ¼¿ä. (Àú´Â ±×³É °è¼Ó º¹»çÇؼ­ ¾¹´Ï´Ù. ¿ì° ¿Ü¿ö...-_-;;;)


´ÙÀ½ °­Á´ ÀÔ·ÂµÈ Á¤º¸¸¦ ºÒ·¯¿À´Â ºÎºÐÀ» ÇÏ°Ú½À´Ï´Ù.
ÀÌÁ¦ ¹æ¸í·Ï ÀÛ¾÷ ½ÃÀÛÀÌ µÇ¾ú³×¿ä. ^^

Áñ perl Çϼ¼¿ä.
ÁÁÀº ÇÏ·çµÇ½Ã±¸¿ä.

Ã߽Š: ÆíÁý±â´Â ¾Æ·¡²¨¸¦ ½áº¸¼¼¿ä.
http://www.happycgi.com/detail.cgi?number=4374&p=1
÷ºÎ ÆÄÀϸñ·Ï
ÆÄÀÏ¸í ¿ë·® ´Ù¿î¼ö µî·Ï½Ã°£
8542-1127test.zip 645 B 199 ȸ 2001-11-27 00:19:02
Ãßõ½ºÅ©·¦¼Ò½ºº¸±â ¸ñ·Ï
ÀÌÀü°Ô½Ã±Û Win95/98¿¡¼­ Active Perl ¼³Ä¡Çϱâ 2001-10-17 04:22:22
´ÙÀ½°Ô½Ã±Û ÅÚ³ÝÀ¸·Î DBI ¼³Ä¡Çϱâ 2002-01-17 20:35:29