473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Running MySQL script in Perl

Hi All,
I'm having a problem executing a MySQL query witihin Perl and was hoping that someone will be able to help me in my moment of stress.

When I run the below script I get this error:

'Can't call method "prepare" on an undefined value at C:\Perl\Jimmy\Testing2.pl line 73'

Line 73 refers to 'e.badge as Badge, \'. The MySQL query runs fine in MySQL, but not sure where I'm going wrong in getting the Perl script to work. Any help would be greatly appreciated.

Jimmy

Expand|Select|Wrap|Line Numbers
  1. use DBI ;
  2. use MIME::Lite ;
  3. use Net::SMTP;
  4.  
  5. my @my_data;
  6. my ($msg_body, $my_table, $result) ;
  7.  
  8. sub OpenMySQL {
  9.  
  10. $dbh = DBI->connect('dbi:mysql:host=167.67.61.69;sid=esd','root','root',{RaiseError => 1, AutoCommit => 0});
  11. if ($dbh) {
  12.         # print "\tConnected!\n";    
  13.  
  14.     } else {
  15.          die "Cannot connect to MySQL" ;
  16.         }
  17. }
  18.  
  19.  
  20. sub CloseMySQL {
  21.  
  22.     $dbh->disconnect;
  23.     if ($dbh) {
  24.             # print "\tDisconnected\n";
  25.  
  26.         } else {
  27.             die "Could not disconnect";
  28.             }
  29. }
  30.  
  31.  
  32. sub RunQueries {
  33.  
  34.  $sth = $dbh->prepare("select distinct concat(e.LastName, ' ', e.Name) as Name, \
  35.              e.badge as Badge, \
  36.              curdate() as 'Date' \
  37.             FROM esduser e \
  38.             LEFT JOIN checkesd c on e.badge = c.badge\
  39.             and c.Date > curdate() \
  40.             where c.badge is null \
  41.             order by e.LastName");
  42.  
  43.   $sth->execute() || die "\tCould not execute query\n";
  44.   $result = $dbh->selectall_arrayref($sth);
  45.  
  46.   $sth->finish; 
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
Jan 19 '09 #1
2 2890
KevinADC
4,059 Expert 2GB
Look in the DBI documentation to properly add error checking to your script. The problem appears to be that $sth is not getting defined. My SQL is too rusty to try and debug your query but it looks odd. What are all the '\' for in the query?
Jan 19 '09 #2
Icecrack
174 Expert 100+
as Kevin said:

Why are you putting \ (Backslashes) in

Expand|Select|Wrap|Line Numbers
  1.  $sth = $dbh->prepare("select distinct concat(e.LastNa
  2. me, ' ', e.Name) as Name, \
  3.  
  4.              e.badge as Badge, \
  5.              curdate() as 'Date' \
  6.             FROM esduser e \
  7.             LEFT JOIN checkesd c on e.badge = c.badge\
  8.             and c.Date > curdate() \
  9.             where c.badge is null \
  10.             order by e.LastName");
  11.  
Perl does not need this it will read the whole (" ..... ") with out the \ like linux.
Jan 20 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Daniel Tonks | last post by:
Here's the situation: I have a Perl-based forum that I wrote myself. It currently supports user accounts, but these are stored in a flat text file (as is everything else for that matter). I'm...
1
by: Cern | last post by:
Is it somebody out there who has made a migration from an Oracle server to an MySQL server?? The scenario is as simply: I've got a Oracle 8 server with a database with content that I want to...
5
by: Bob MacBob | last post by:
Hi all, I have two scripts: 1/ parser.pl which parses a text file and stuffs the relevant data into a mySQL DB - works fine no probs there 2/ importer.pl which I want to run through all the...
10
by: shumaker | last post by:
I don't need a detailed description of a solution(although I wouldn't mind), but I am hoping someone could tell me in general the best path to go about accomplishing a task, since I don't know all...
1
by: andipfaff | last post by:
Hi there, I am fighting with my MysQL database in order to get french and cyrillic characters properly displayed on my website. I've created tables with latin1 charset. My Perl script on the...
5
by: Sport Girl | last post by:
Hi again my great online assistants, just would like to say that i'm testing the script under unix , and after researches on the internet, i have realised that to resolve 500 Internal Server Error,...
9
by: idorjee | last post by:
Hi guys, I have a small problem with my Perl-CGI script, and I would appreciate if anyone can help me out with this. I'm trying to get this done in two stages. 1st to get a bunch of info from the...
6
by: aravindtn | last post by:
i have a netwok,and i have a perl script running on a machine(say machine1). the purpose of the script is to login to each of the other machines using ssh. i am able to logon to other machne (say...
11
by: bthalapathi | last post by:
I have written a script to connect the mysql db #!/usr/bin/perl -w use DBI; #definition of variables $db="MYTEST"; $host="localhost"; $user="root"; $password="rootpass";
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.