Hi,
I have this program written in Perl and to be tested on Linux-Fedora.
#!/usr/bin/perl
use Mysql;
$host = "localhost";
$database = "DVDRentals";
$tablename = "Orders";
$user = "root";
$pw = "password";
# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);
# SELECT DB
$connect->selectdb($database);
# DEFINE A MySQL QUERY
$myquery = "SELECT * FROM $tablename";
# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);
# HTML TABLE
print "<table border='1'><tr>
<th>OrderID</th>
<th>CustID</th>
<th>EmpID</th></tr>";
# FETCHROW ARRAY
while (@results = $execute->fetchrow()) {
print "<tr><td>"
.$results[0]."</td><td>"
.$results[1]."</td><td>"
.$results[2]."</td></tr>";
}
print "</table>";
When I run the program at the command-line with the command perl mysqlquery.pl, here is what comes up as a result of it.
[root@localhost PracPerl]# perl mysqlquery.pl
Mysql connect('database=DVDRentals;host=localhost','root',...) failed: Access denied for user 'root'@'localhost' (using password: YES) at mysqlquery.pl line 12
Can't call method "selectdb" on an undefined value at mysqlquery.pl line 15.
I am the root user of the system and that is why I have put root as user in the program and kept the password field empty once and then run the program so see if it works but it does not. And even with the password as password it does not. So I tried to check all the installed packages that relate to Perl on the system as follows:
[root@localhost PracPerl]# rpm -qa | grep perl
perl-URI-1.35-2.2
mod_perl-2.0.2-5.1
perl-Net-DNS-0.55-1.1.2
perl-Digest-HMAC-1.01-14.2
perl-DBD-MySQL-3.0002-2.2.2
perl-libwww-perl-5.805-1.1
perl-XML-RegExp-0.03-2.fc5
perl-Digest-SHA1-2.11-1.2
perl-String-CRC32-1.3-3.FC5.2
perl-HTML-Parser-3.50-1
newt-perl-1.08-9.2.1
perl-DBD-Pg-1.43-2.2.2
perl-5.8.8-5
perl-DateManip-5.44-1.2
perl-DBI-1.50-2.2
perl-Compress-Zlib-1.41-1.2.2
perl-HTML-Tagset-3.10-2.1
perl-XML-XQL-0.68-2.fc5
perl-XML-Parser-2.34-6.1.2.2
perl-Parse-Yapp-1.05-35.fc5
perl-BSD-Resource-1.24-3.2.2
perl-Net-IP-1.24-2.2
perl-SGMLSpm-1.03ii-16.2
perl-XML-DOM-1.44-2.fc5
I just assume that here this package perl-DBD-MySQL-3.0002-2.2.2, is the one is required to make Perl talk to MySQL. Am I right here? How could I solve the problem here of connecting Perl and MySQL? Please guide me as I am a newbie. Thanks.