LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-27-2012, 06:21 PM   #1
xman fiji
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Rep: Reputation: Disabled
Can't locate object method "connect" via package "mysql" (perhaps you forgot to load


i m getting this message when i m trying to run my perl script...please can any one hellp me....

* i have already set cpan
* and installed mysql.pm
* installed DBI.pm


Can't locate object method "connect" via package "mysql" (perhaps you forgot to load "mysql"?) at ./scriptfTesting.cgi line 46.
 
Old 06-27-2012, 07:22 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
If I use code with this pattern:

Code:
use DBI ;

$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" ;

$dbh = DBI->connect($dsn, $user, $password) ;
of course with the generalities replaced with specifics, but then comment out the "use" line,
I get the message:

Quote:
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at mysql.pl line 5.
so maybe you left out a "use"?
 
Old 06-27-2012, 08:07 PM   #3
xman fiji
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Now i m getting this problam

root@Ubuntu-Server:/var/www/corporate/cgi-bin# ./scriptfTesting.cgi
Name "main::hostname" used only once: possible typo at ./scriptfTesting.cgi line 50.
Name "main:assword" used only once: possible typo at ./scriptfTesting.cgi line 54.
Name "main:w" used only once: possible typo at ./scriptfTesting.cgi line 41.
Name "main:ort" used only once: possible typo at ./scriptfTesting.cgi line 50.
Name "main::connect" used only once: possible typo at ./scriptfTesting.cgi line 58.
Name "main::host" used only once: possible typo at ./scriptfTesting.cgi line 40.
Name "main::dbh" used only once: possible typo at ./scriptfTesting.cgi line 54.
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Thu Jun 28 00:56:15 2012 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-type: text/html


<html>
<head>
<title>Corporate User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#0099ff">

Use of uninitialized value $hostname in concatenation (.) or string at ./scriptfTesting.cgi line 50.
Use of uninitialized value $port in concatenation (.) or string at ./scriptfTesting.cgi line 50.
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at ./scriptfTesting.cgi line 54.
root@Ubuntu-Server:/var/www/corporate/cgi-bin#
____________________________________________________________________________________________________ _____________________

This is perl script

#! /usr/bin/perl -w


#use strict;
#use DBI;
#use Mysql::Statement;
#use strict;
#use warnings;
use DBI ;
#my @ary = DBI->available_drivers();
#print join("\n", @ary), "\n";

#use DBI;
#use Mysql;

# Print out the web page
print "Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"; # Date in the past
print "Last-Modified: " . scalar gmtime() . " GMT\n"; # always modified
print "Cache-Control: no-cache, must-revalidate\n"; # HTTP/1.1
print "Pragma: no-cache\n"; # HTTP/1.0
print "Content-type: text/html\n\n";
#print "'$FORM{EngineerName}'";

print <<EOHTML;

<html>
<head>
<title>Corporate User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#0099ff">

EOHTML

if (1) {
#####################################################
# Set up variables
$database = "mydb"; # database to connect to
$user = "root";
$host = "127.0.0.1"; # host
$pw = "XXXXXX";
#####################################################
}

# PERL MYSQL CONNECT()
###$connect = mysql->connect($host, $database, $user, $pw);
###my $dbh =mysql->connect($host, $database, $user, $pw);


$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" ;

# SELECT DB
###$connect->selectdb($database);
$dbh = DBI->connect($dsn, $user, $password) ;

$myquery = "select Date,CompanyName,IPAddress,SubnetMask,EngineerName from Corporate"; #where EngineerName= '$FORM{EngineerName}' order by Date";

$execute = $connect->query($myquery);


print <<EOHTML;

<hr>
<br><font face="Tahoma" size="3"><b><u>Check Corporate User Information</u></b></font></br><hr>
<table border=1 bgcolor="#ADFF2F" cellpadding=5 width=90%>
<tr>
<th>Date</th><th>CompanyName</th><th>IPAddress</th><th>SubnetMask</th><th>EngineerName</th>
</tr>

EOHTML

while (@data = $execute->fetchrow_array()) {
print ("<tr>\n");
print ("<td><font face=tahoma size=2>".($data[0])."</font></td>\n");
print ("<td><font face=tahoma size=2>".($data[1])."</font></td>\n");
print ("<td><font face=tahoma size=2>".($data[2])."</font></td>\n");
print ("<td><font face=tahoma size=2>".($data[3])."</font></td>\n");
print ("<td><font face=tahoma size=2>".($data[4])."</font></td>\n");
print ("</tr>\n");
}

print <<EOHTML;
</table>
<hr>
<br>
</font>
</td>
</tr>

<tr><td valign=top>

</font>
</td>
</tr>
</tr>
<tr><td valign=top>
<font>
</font>
</td>
</tr>
</table>
<hr>
</center>
EOHTML

print <<EOHTML;

</body>
</html>

EOHTML
____________________________________________________________________________________________________ _______________________________



Quote:
Originally Posted by kakaka View Post
If I use code with this pattern:

Code:
use DBI ;

$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" ;

$dbh = DBI->connect($dsn, $user, $password) ;
of course with the generalities replaced with specifics, but then comment out the "use" line,
I get the message:



so maybe you left out a "use"?
 
Old 06-27-2012, 08:34 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Start by amending
Code:
#! /usr/bin/perl -w


#use strict;
#use DBI;
#use Mysql::Statement;
#use strict;
#use warnings;
use DBI ;
#my @ary = DBI->available_drivers();
#print join("\n", @ary), "\n";

#use DBI;
#use Mysql;
to
Code:
#! /usr/bin/perl -w

use locale;             # Ensure correct charset for eg 'uc()'
use DBI;                # Database connections
use strict;             # Enforce declarations
These var names
Code:
$database = "mydb"; # database to connect to
$user = "root";
$host = "127.0.0.1"; # host
$pw = "XXXXXX";
do not match these
Code:
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" ;
I strongly advise dropping the cgi bit and just get the core code working as a cmd line .pl, then you can extend it to work as a cgi.

http://perldoc.perl.org/
http://www.perlmonks.org/?node_id=284436
http://www.perlmonks.org/?node=Tutorials

You can run a pre-flight check thus
Code:
perl -wc myprog.pl
Ensure you ALWAYS leave -w switch on (equiv to 'use warnings) and also the 'use strict' cmd; they'll save you a boat-load of trouble later.
 
Old 06-27-2012, 09:13 PM   #5
xman fiji
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
now i m getting this...

Execution of ./scriptfTesting.cgi aborted due to compilation errors.
root@Ubuntu-Server:/var/www/corporate/cgi-bin# ./scriptfTesting.cgi
Global symbol "$database" requires explicit package name at ./scriptfTesting.cgi line 41.
Global symbol "$user" requires explicit package name at ./scriptfTesting.cgi line 42.
Global symbol "$host" requires explicit package name at ./scriptfTesting.cgi line 43.
Global symbol "$pw" requires explicit package name at ./scriptfTesting.cgi line 44.
Global symbol "$dsn" requires explicit package name at ./scriptfTesting.cgi line 53.
Global symbol "$database" requires explicit package name at ./scriptfTesting.cgi line 53.
Global symbol "$hostname" requires explicit package name at ./scriptfTesting.cgi line 53.
Global symbol "$port" requires explicit package name at ./scriptfTesting.cgi line 53.
Global symbol "$dbh" requires explicit package name at ./scriptfTesting.cgi line 57.
Global symbol "$dsn" requires explicit package name at ./scriptfTesting.cgi line 57.
Global symbol "$user" requires explicit package name at ./scriptfTesting.cgi line 57.
Global symbol "$password" requires explicit package name at ./scriptfTesting.cgi line 57.
Global symbol "$myquery" requires explicit package name at ./scriptfTesting.cgi line 59.
Global symbol "$execute" requires explicit package name at ./scriptfTesting.cgi line 61.
Global symbol "$connect" requires explicit package name at ./scriptfTesting.cgi line 61.
Global symbol "$myquery" requires explicit package name at ./scriptfTesting.cgi line 61.
Global symbol "@data" requires explicit package name at ./scriptfTesting.cgi line 75.
Global symbol "$execute" requires explicit package name at ./scriptfTesting.cgi line 75.
Global symbol "@data" requires explicit package name at ./scriptfTesting.cgi line 77.
Global symbol "@data" requires explicit package name at ./scriptfTesting.cgi line 78.
Global symbol "@data" requires explicit package name at ./scriptfTesting.cgi line 79.
Global symbol "@data" requires explicit package name at ./scriptfTesting.cgi line 80.
Global symbol "@data" requires explicit package name at ./scriptfTesting.cgi line 81.
Execution of ./scriptfTesting.cgi aborted due to compilation errors.
root@Ubuntu-Server:/var/www/corporate/cgi-bin#

what should i do now
 
Old 06-27-2012, 09:18 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As per my comment
Code:
use strict;             # Enforce declarations
means what it says; you have to declare your vars.
See the links I gave you ..
Here's a short extract from one of my progs

Code:
sub program_ctrl
{
    my (
        %assigned_stages,       # list of stages set in cfg file
        $curr_stage,            # stage to process
        $hastus_file,           # Hastus file to get
        %bus_stops              # x-ref bnum:pos => (sign) id
        );
.
.
.
}
Do use subs (aka functions) to break your code into manageable pieces.

You should have started with that pre-flight check cmd and fixed any errors BEFORE you try to actually run it.
 
1 members found this post helpful.
Old 06-27-2012, 09:51 PM   #7
xman fiji
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
but how can i declare the vars and where should i do that ...?
 
Old 06-27-2012, 11:53 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you read those links you'll see I've just shown you how ...
 
Old 07-10-2012, 07:51 PM   #9
xman fiji
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
any other way ....still cant get those links work ....
 
Old 07-11-2012, 08:05 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. Drop the space in the shebang line
Code:
#! /usr/bin/perl -w

# should read

#!/usr/bin/perl -w
Quote:
any other way ....still cant get those links work ....
What does that mean; please use proper English and describe specific problems; not 'it doesn't work' ..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't locate object method "path" via package "Autom4te::Request" at/usr/bin/autom4te wjh513 Linux - Software 1 08-13-2010 02:31 PM
Perl DBI error cannot locate object method "require -version" nanda22 Programming 0 08-26-2009 08:32 AM
Can't locate object method "splitpath" via package "PACK001" at /usr/lib/perl5/5.8.8/ sajigeorge Linux - Software 1 01-11-2009 06:33 AM
perl install error: Can't locate object method "new" via package "Module::Build::Vers powah Linux - Software 0 10-24-2006 01:57 PM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration