Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
If you click on the link below it displays a list of all proeprties: http://www.goarealestates.com/cgi-bin/housing.pl?search=1&category=Buy&;submit=Go!!!
Within my script file, i have a statement as below which connects to the database
And the function db_connect() is as below:-$dbh = db_connect($database,$user,$password);
I have also got a db.cfg file which is as belowsub db_connect { ($database,$user,$password) = @_; my $h = DBI->connect("DBI:mysql:$database", $user, $password) or printError("Unable to connect to $database" . $DBI::errstr); return $h; }
But the present hosting provider has given an example of how to connect to the mysql database as below:-# script config file $database = "shafi"; $user = "shafi"; $password ="shafi"; 1;
The DBI->connect statement is different and deosnt seem to work. Could someone tell me how my function should change to adapt to this hsoting provider.================================================= #!/usr/bin/perl use DBI; print "Content-type:text/html\n\n"; $db_handle = DBI->connect("dbi:mysql:database=dbxxxxxxxx;host=dbxxx.on +eandone.co.uk;user=dboxxxxxxxx;password=xxxxxxxx") or die "Couldn't connect to database: $DBI::errstr\n"; $sql = "SELECT * FROM puretest"; $statement = $db_handle->prepare($sql) or die "Couldn't prepare query '$sql': $DBI::errstr\n"; $statement->execute() or die "Couldn't execute query '$sql': $DBI::errstr\n"; while ($row_ref = $statement->fetchrow_hashref()) { print "Name <b>$row_ref->{name}</b> has email address::< +b>$row_ref->{email}</b>.<br>"; } $db_handle->disconnect(); ===================================================
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI->connect problem
by kyle (Abbot) on Jan 20, 2007 at 23:55 UTC | |
by Herkum (Parson) on Jan 21, 2007 at 01:43 UTC | |
|
Re: DBI->connect problem
by Joost (Canon) on Jan 20, 2007 at 23:52 UTC | |
|
Re: DBI->connect problem
by logie17 (Friar) on Jan 21, 2007 at 06:28 UTC |