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. |
If I use code with this pattern:
Code:
use DBI ; I get the message: Quote:
|
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::password" used only once: possible typo at ./scriptfTesting.cgi line 54. Name "main::pw" used only once: possible typo at ./scriptfTesting.cgi line 41. Name "main::port" 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:
|
Start by amending
Code:
#! /usr/bin/perl -w Code:
#! /usr/bin/perl -w Code:
$database = "mydb"; # database to connect to Code:
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" ; 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 |
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 |
As per my comment
Code:
use strict; # Enforce declarations See the links I gave you .. Here's a short extract from one of my progs Code:
sub program_ctrl You should have started with that pre-flight check cmd and fixed any errors BEFORE you try to actually run it. |
but how can i declare the vars and where should i do that ...?
|
If you read those links you'll see I've just shown you how ...
|
any other way ....still cant get those links work ....
|
1. Drop the space in the shebang line
Code:
#! /usr/bin/perl -w Quote:
|
All times are GMT -5. The time now is 10:46 PM. |