Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep getting error trying to access database using perl...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have created a database using cpanel/mysql called gtName_test with a table called candy...

however, i can't figure out how to access the database...

***

#!/usr/bin/perl -w

require "pl/subs.pl";
require "pl/siteGuide.pl";

use strict;
use CGI qw:)standard);
use DBI;

my $dbh = DBI->connect('dbi:mysql:gtName_test','','');

*** etc ***

although the script doesn't throw any error, i use the following test:

**
my $sql = "select name from candy";

my $sth = $dbh->prepare($sql);

$sth->execute || die "Could not execute SQL statement ... maybe invalid?";

while (@row=$sth->fetchrow_array)
{ print "@row\n" }

**

i have the correct table, 'candy', and i have a name field...

i'm following stuff for perl/mysql online but none of it works.

help please?

- g
 
to help understand your problem try adding the following the following lines:

use CGI::Carp 'fatalsToBrowser';

this way, if there is a problem, the error should find its way to the browser...

also, change,

my $dbh = DBI->connect('dbi:mysql:gtName_test','','');
to
my $dbh = DBI->connect('dbi:mysql:gtName_test','','')
or die ("cannot connect to database");

check also that you can connect to your db with no username and password...

correct format is normally:

$dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password")

hope this helps ...
 

okay...i'm getting somewhere...i added the use:CARP in there and now i get an error in the browser:

Access denied for user: 'gtName_test@localhost' (Using password: NO) at index.pl line 16.

so i guess i'm not granted access? i tried with password and username. no go.

i am using the mysql that the ISP has given me. i don't know how to administer any test to see if i have root.

- g
 
try being a little more specific on the database connection, e.g.

my $dbh = DBI->connect(DBI:mysql:host=localhost;database=gtName_test","$user","$pas");

just change user and pass to those specified by your ISP.

this may help, other than that contact your ISP for more information.
 
it also worth to check if you actually can login into the mysql instance with your user name and "no password".
If you have a command line access to the mysql db server try to login into mysql as:
% mysql -u youruser -pyourpassword gtName_test
--well if you do not have password to the user just skip the "yourpassword" portion.
If mysql was installed from the scratch - it may contain some default entries that prevent anonymous user to connect.
To fix that you do have to login into the mysql server as root :
%mysql -u root mysql
and run following :
>DELETE FROM user where User=""; flush privileges;
Hope it helps,
WR.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top