Gossamer Forum
Home : General : Perl Programming :

Is it possible to and how do you reach another server

Quote Reply
Is it possible to and how do you reach another server
The server that has a cgi script does not have MySQL installed. MySQL is on another server on a different domain were the database is. I can't seem to get to the data base from the script. I have a configuration file that has the parameters and this cgi is call from the one that wants to access the database. Let me show you the two scripts, the first one is configure.pl as follows:

sub configure {
###############################
# CGI CONFIGURATION VARIABLES
###############################
$mailprogram = "/usr/sbin/sendmail -t";
$database = "matchpro";
$hostname = "mysql.rcrrich.com"; # added this
$port = "3306";
$mysqlusername = "name"; #just here for you
$mysqlpassword = "pass"; # not real use or pass

This is just the part that is supposed to call MySQL and open the database matchpro when called from the other scripts. All the scripts call this one file to get many of the perameters. Now the next script is the one that gets the info to add to the database matchpro. This one is called add.pl

#!/usr/bin/perl -s
use Socket;
require "configure.pl";
&configure;
open (HEADERHTML, "$headerhtml");
@header = <HEADERHTML>;
close HEADERHTML;
open (FOOTERHTML, "$footerhtml");
@footer = <FOOTERHTML>;
close FOOTERHTML;

$orderid = &generateorderid;
$profilenumber = $orderid;

&form_parse;
$AdHeadline = $FORM{'AdHeadline'};
$EmailAddress = $FORM{'EmailAddress'};
$TelephoneAreaCode = $FORM{'TelephoneAreaCode'};
$City = $FORM{'City'};
$StateProvince = $FORM{'StateProvince'};
$Zip = $FORM{'Zip'};
$Country = $FORM{'Country'};
$RelationshipPreference = $FORM{'RelationshipPreference'};
$SexualPreference = $FORM{'SexualPreference'};
$Username = $FORM{'Username'};
$Password = $FORM{'Password'};
$VerifyPassword = $FORM{'VerifyPassword'};
$SmokingPreference = $FORM{'SmokingPreference'};
$DrinkingPreference = $FORM{'DrinkingPreference'};
$MaritialStatus = $FORM{'MaritialStatus'};
$HaveChildren = $FORM{'HaveChildren'};
$BodyBuild = $FORM{'BodyBuild'};
$Height = $FORM{'Height'};
$Religion = $FORM{'Religion'};
$Race = $FORM{'Race'};
$AstrologicalSign = $FORM{'AstrologicalSign'};
$Age = $FORM{'Age'};
$Occupation = $FORM{'Occupation'};
$MiscComments = $FORM{'MiscComments'};
$MiscComments =~ s/ /\|/g;
$MiscComments =~ s/\s/\|/g;
$MiscComments =~ s/\|+/ /g;

use DBI;
$dbh = DBI->connect("DBI:mysql:$database:$hostname:$port, "$mysqlusername", "$mysqlpassword") or die "Unable to connect to Data: $dbh->errstr\n");

print "Content-type: text/html\n\n";
&printheader;
&errcheck;
&checkuniqueusernames;
&checkuniqueemails;
&savedata;
&printconfirmation;
&printfooter;
&emailmember;

$dbh->disconnect;

If I # out the $dbh = DBI->connect........

the script starts to work, so it seems that as soon as the script reachs $dbh it crashes with a 500 error

Can anyone help or is this not possible??

rexxx
rexxx webmaster
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
The way I do it is just pointing to sql.server.com (obviously different for every host). You just replace where it normally uses 'localhost'. I'm not quite sure why you have them in 2 different files. If someone is gonna hack your script, they will do it just as easily if they are in a seperate file Wink You appear to me missing a } in the config sub (the ending of it). Not sure if that is whats causing the error, or if you just didnt paste it here ;)

Hope that helps a little.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
Make sure configure.pl has a 1; at the bottom if you are requiring it into your main script.

Also check your error log. The more info you can provide the easier it is to help.
Quote Reply
Re: [RedRum] Is it possible to and how do you reach another server In reply to
Yes got that

}
1; # Return true

It just crashes as soon as the script hits the row I stated

$dbh
rexxx webmaster
Quote Reply
Re: [AndyNewby] Is it possible to and how do you reach another server In reply to
The scripts as stated are just the areas were the call to the mysql database is. I need to know what to call the database with I have tried many ways but it seems as soon as the script hits the line $dbh it crashes with a 500 error. I would post the whole script if you think other parts would help to show how to call the mysql database.
rexxx webmaster
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
Look in your error_log as to what produces the error. This should give you a better clue. MySQL should return the exact error why is was unable to connect to the database.

- wil
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
It is dying because it can't connect to mysql for some reason.

If you don't want to see a 500 you can print $dbh->errstr rather than die()ing
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
Try using fatalsToBrowser too in your scripts. Its much easier than having to look in your logs, and very often it helps you sort your problems out with a HELPFUl errro message Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Is it possible to and how do you reach another server In reply to
Great give me an example
rexxx webmaster
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
A please and thank you may be nicer Wink

Try adidng this just below your location to perl;

Code:
use CGI::Carp qw(fatalsToBrowser);

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Is it possible to and how do you reach another server In reply to
I get this now: Software error:

Execution of add.pl aborted due to compilation errors.

This happens when I don't # out the $dbh =.... line. If I # this line I get the form telling me about not adding a feild in the form which would be correct as I did not fill in the form other then push the send button which then call the add.pl to get the information that the user would input.

So I take it that mysql doesn't have to be running on the same server as the script.

The script just needs to point to the mysql database which is on mysql.rcrrich.com were matchpro is. But for some reason it crashes everytime this line doesn't have the # in front of it. The $dbh = line that is. So it just must be the way I am calling the database. That's the million dollar question. How is that done?????
rexxx webmaster
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
As suggested it would be best to print the error to the browser or check your error log.

If you aren't sure what the error means then paste it here.
Quote Reply
Re: [RedRum] Is it possible to and how do you reach another server In reply to
I did add your line and I also changed the line in the add.pl file to this:

FROM THIS:

use DBI;
#$dbh = DBI->connect("DBI:mysql:$mysqldatabase:$mysqlhostname:$mysqlport, "$mysqlusername", "$mysqlpassword") "$dbh->errstr\n";

TO THIS:
local-system> $dbh = DBI->connect DBI:mysql:matchpro -h mysql.rcrrich.com -P 3306 -u username -ppassword "$dbh->errstr\n";

AND NOW I GET ERROR: Software error:

Unrecognized file test: -h at add.pl line 60.

It seems that I am reaching mysql now but not properly.
rexxx webmaster
Quote Reply
Re: [rexxx] Is it possible to and how do you reach another server In reply to
Eek. What is local-system> ?

You are getting a little mixed up.

Could you attach the whole script as an attachment and I'll take a look.
Quote Reply
Re: [RedRum] Is it possible to and how do you reach another server In reply to
Ok here are the two files this is not all as there are 20 cgi files but they all work the same way. I also don't have the right info pertaining to user and password or site. I hope this is ok!
rexxx webmaster
Quote Reply
Re: [RedRum] Is it possible to and how do you reach another server In reply to
By George I think I got it working!!!!
rexxx webmaster