Gossamer Forum
Home : General : Databases and SQL :

Where I need to change ?

Quote Reply
Where I need to change ?
Hello:

I am using one cgi/perl scripts which works perfect when I use with mysql host name as "localhost". But now I already change my hosting service and now it doesn't work. So, I need to replace mysql.neureal.com in stead local host. But I am not sure where I have to change. Here is the file:
-----------------------------------------------------------------


Code:

##########################################
## Create a connection to the database. ##
##########################################
sub Create_DB_Connection{
use DBI;
$DSN = "DBI:mysql:database1";
$user = "admin";
$pw = "adminonly";
$dbh = DBI->connect($DSN,$user,$pw)
|| die "Cannot connect: $DBI::errstr\n" unless $dbh;
return;
} # End of Create_DB_Connection subroutine.
##########################################

##########################################
## Executes the SQL command and then ##
## returns to the calling area of the ##
## program. ##
##########################################
sub Do_SQL{
eval{
$sth = $dbh->prepare($SQL);
}; # End of eval

# Check for errors.
if($@){
$dbh->disconnect;
print "Content-type: text/html\n\n";
print "An ERROR occurred! $@\n<P>";
exit;
} else {
$sth->execute;
} # End of if..else
return ($sth);
} # End of Do_SQL subroutine
#################################################################

####################################
### Filter - Gets rid of ###
### characters that screw up the ###
### program. ###
####################################
sub filter{
$_[0]=~s/\'/\\\'/g;
$_[0]=~s/\;//g;
return $_[0];
} # End of filter subroutine
#################################################################


sub parse {
my (@pairs, $pair, $name, $value);
if (uc($ENV{'REQUEST_METHOD'}) eq "POST"){read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});}
else{$buffer = $ENV{'QUERY_STRING'};}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("C", hex($1))/eg;
$IN{$name} = $value;
}
}


sub HTMLdie {
local($msg,$title)= @_ ;
$title || ($title= "CGI Error") ;
print <<EOF;
<html><head>
<title>$title</title>
</head><body>
<h1>$title</h1>
<h4>$msg</h4>
</body></html>
EOF
exit ;
}

sub LoadHeader {
open(FILE, "header.html");
$header = join('', <FILE>);
close(FILE);
}

sub LoadFooter {
open(FILE, "footer.html");
$footer = join('', <FILE>);
close(FILE);
}


1; # Required or won't work!
-----------------------------------------------------------------

Thanks in advance.

Sincerely yours,
Rana

Last edited by:

Wil: Sep 8, 2002, 2:54 PM
Quote Reply
Re: [rana] Where I need to change ? In reply to
Change:

$DSN = "DBI:mysql:database1";

to:

$DSN = "DBI:mysql:database1:mysql.neureal.com";

I'd suggest using CGI.pm instead of the archaic parsing routine but as you are new to perl I won't go into that now.
Quote Reply
Re: [Paul] Where I need to change ? In reply to
Hi Paul:

Thank you very much for your help. Now it works :)

Rana Laugh
Quote Reply
Re: [rana] Where I need to change ? In reply to
Hi rana

Welcome to the forum!

I've altered your message to wrap your code in [code] tags so that the forum software preserves the formatting of your code.

The forum boasts a number of custom tags you can use in your posts, or you can use the 'Advanced Editor' to format your post using a graphical interface, whichever you prefer. Here's the link to the list of available formatting tags:

http://www.gossamer-threads.com/....cgi?do=markup_help;

Hope this helps.

- wil