CGI程序里创建数据库连接

CGI程序里创建数据库连接

CGI程序里创建数据库连接
各位老师,
我在CGI 程序里创建了一个数据库连接(用的是MYSQL),程序一遇到连接的句子,就什么也没有了[CCB]10[/CCB]
没有人肯帮忙?
朋友们请帮个忙,指点一下!!!
你的描述不清楚,或者你可.
你的描述不清楚,或者你可以贴程序。

ps
链接数据库一般使用DBI,注意出错的时候看看 $DBI::errstr 变量里面是否有错误信息。
就不这个程序
#! c:\perl\perl.exe
# filename: operate_db2.pl
# using a mysql database
# 这是一个用表单收集信息的CGI程序, 将信息插入mysql数据库, 然后用一个表格打印出来

use warnings;
use strict;
use DBI;
use DBD::mysql;
use CGI::Pretty qw(:standard);

print header(), start_html("Registration Form"),
h1("Registration Form");

if (param("No") || !param()){
registrationForm();
}
elsif (!param("Yes")){
my $first = param("FIRST");
my $last = param("LAST");
my $email = param("EMAIL");
my $phone = param("PHONE");
my $land = param("CONTINENT");
my $os = param("OS");
my $time = param("HOURS");
my $value = param("RATING"); #25

if ($phone !~ /\(\d{3} \) \d{3} - \d{4}/x){
print "Please enter your phone number in the correct format.", br();
registrationForm();
}
elsif (($time !~ /\d+/x) || $time < 0 || $time > 24){
print "Please enter an integer for hours that is ",
"between 0 and 24", br();
registrationForm();
}
else{
print h4("You entered"), br(),
"Name $first $last", br(),
"E - mail $email", br(),
"Phone $phone", br(),
"Continent $land", br(),
"OS $os", br(),
"Hours Use Product: $time", br(),
"Rating of Product: $value", br(),

start_form(),
hidden(-name => 'FIRST'), hidden('LAST'),
hidden(-name => 'EMAIL'), hidden('PHONE'),
hidden(-name => 'CONTINENT'), hidden(-name => 'OS'), #49
hidden(-name => 'HOURS'), hidden(-name => 'RATING'),
"Is the information correct?", br(),
submit(-name => 'Yes'), submit(-name => 'No'),
end_form();
}
}
else {
my $first = param("FIRST");
my $last = param("LAST");
my $email = param("EMAIL");
my $phone = param("PHONE");
my $land = param("CONTINENT");
my $os = param("OS");
my $time = param("HOURS");
my $value = param("RATING");

if ($phone =~ /\(\d{3}\) \d{3} - \d{4}/x){
my $dbh = DBI -> connect("DBI:mysql:personal_info", "root", "207208", #程序一到这里就不运行
{RaiseError => 1});


print "Thand you for completing the ",
"registration form $first", br(),
"The following information has been recorded:",
br(), br(),
table({-border => 3, -cellspacing => 3},
Tr(th(['Name', 'E-mail', 'Phone Number',
'Continent', 'Os', 'Hours', 'Rating'])),
Tr(td(["$first $last", $email, $phone,
$land, $os, $time, $value])));
}
else{
print "Please enter your phone number in the ",
"correct format", br();
registrationForm();
}
}

print end_html();

sub registrationForm #93
{
print h3("Please fill in all fields and then click proceed"),
start_form(),
table({-cellpadding => 3},
Tr({-valign => 'top'},
td({-width => 300}, strong("First Name:"),br(),
textfield(-name => 'FIRST', -size => 15)),
td(strong("Last Name:"), br(),
textfield(-name => 'LAST', -size => 15))),

Tr({-valign => 'top'},
td(strong("E-mail Address"), br(),
textfield(-name => 'EMAIL', -size => 25)),
td(strong("Phone Numbers"), br(),
textfield(-name => 'PHONE', -size => 20), br(),
"Must be of the form (555)555 - 55555"))),

h4("What Continent do you live on?"),
popup_menu(-name => 'CONTINENT',
-value => ['North America', 'South America', 'Asia',
'Europe', 'Australia', 'Africa', 'Antarctica']),
br(),
h4("Which operating system are you currently running?"), #116
radio_group(-name => 'OS',
-value => ['window 98', 'windows NT',
'Macintosh', 'Linux', 'Other']),
br(),
h4("How many hours a day do you use our product?"),
textfield(-name => 'HOURS', -size => 3),

h4("How would you rate our product on a scale of 1 - 5"),
radio_group(-name => 'RATING',
-value => ['1', '2', '3', '4', '5']),
br(),
submit(-name => 'proceed'),
end_form();
}
谢谢fkiori指点,我用的是 windows XP 的 IIS 服务, 程序运行时没有报错, 就是遇到 connect 句子就中断,请大家帮我看一下
my $dbh = DBI -> co.
my $dbh = DBI -> connect("DBI:mysql:personal_info", "root", "207208", #程序一到这里就不运行
{RaiseError => 1});
没有指定链接的mysql服务器

请参考我的用法。
$self->{_DBH} = DBI->connect("DBI:mysql:$cfg->{db_name}:$cfg->{db_host}:$cfg->{db_port}", $cfg->{db_user}, $cfg->{db_pwd},);

$self->die("$DBI::errstr") if (!$self->{_DBH});
我是不是这样用? 这两个$self, $cfg 散列引用不知道是怎么来的?
my ($self, $cfg);
$self->{_DBH} = DBI->connect("DBI:mysql:$cfg->{'personal_info'}:$cfg->{'localhost'}:$cfg->{'3306'}", $cfg->{'root'}, $cfg->{'207208'},);

$self->die("$DBI::errstr") if (!$self->{_DBH});
我只是给你例子。你不需要.
我只是给你例子。你不需要用我的 $self 和 $cfg 啊
你把对应的值替换上就可以了
这是程序的报错信息 这是程序的报错信息
DBI connect('database=personal_info;host=localhost;port=3306','root',...) failed: Can't create TCP/IP socket (10093) at D:\site\myWeb\operate_db3.pl line 11
cannot make connect: Can't create TCP/IP socket (10093) at D:\site\myWeb\operate_db3.pl line 11.
开心, 问题解决了
连接数据库的问题解决了, 可能有两个原因, 一是我的机子中毒太深(近段时间机子中毒了,至使 perl 程序都不能运行了), 第二个可能是使用的 mysql 版本不对. 在重装系统之后, 我下了一个新的 server 版, 今天试用了一下, ok 了. 谢谢指点过我的朋友[CCB]1[/CCB]