473,587 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't call method "prepare" on an undefined value!

7 New Member
I am getting an error that says that I can't call method "prepare" on an undefined value!

Here is what I have as code.... I don't understand what is not defined.

Expand|Select|Wrap|Line Numbers
  1. # opens connection to Access database titled KTC.mdb
  2. # no passwords on our database
  3. $dbh = DBI->connect('dbi:ODBC:KTC');
  4. $connect = DBI->connect('dbi:ODBC:KTC');
  5.  
  6. # sets variable $productID to a value of 1
  7. $productID=1;
  8.  
  9. # prepares query1
  10. # selects elements from Products table where productID is equal to 1
  11. $query1 = "SELECT ProductName, ProductDescription, UnitsInStock, UnitPrice FROM Products WHERE ProductID = $productID";
  12. $query_handle = $connect->prepare($query1);
  13.  
  14. # Executes the SQL statement defined in query1
  15. $query_handle->execute();
  16.  
  17.  
Oct 30 '06 #1
2 12621
miller
1,089 Recognized Expert Top Contributor
Add some error trapping to your code. Most likely your database handle isn't really being created. You'll have to do some more reading up on DBI to determine what the proper connect string is.

http://search.cpan.org/search?query=DB I

One thing I do notice though is that you are not specificing a username or password. I do not know if this is strictly necessary for your database, but I expect that it probably is.

Either way, add the or die statements that you can at least discover where and when you're having a problem, instead of relying and perl failing because of false assumptions like "is this $dbh created?".

Expand|Select|Wrap|Line Numbers
  1. # opens connection to Access database titled KTC.mdb
  2. # no passwords on our database
  3. $dbh = DBI->connect('dbi:ODBC:KTC') or die "Database connection failed.";
  4.  
  5. # sets variable $productID to a value of 1
  6. $productID=1;
  7.  
  8. # prepares query1
  9. # selects elements from Products table where productID is equal to 1
  10. $query1 = "SELECT ProductName, ProductDescription, UnitsInStock, UnitPrice FROM Products WHERE ProductID = $productID";
  11. $query_handle = $dbh->prepare($query1);
  12.  
  13. # Executes the SQL statement defined in query1
  14. $query_handle->execute() or die $dbh->errstr;
  15.  
Oct 30 '06 #2
gmccammon
7 New Member
Thanks, it definitely was not connecting. Although, I tried the same code on another machine and it works. Go figure. Thanks again.
Oct 31 '06 #3

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

Similar topics

14
24085
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to convert n = "" # init new string for i in str: if i in chr: # if special character in str n+='\\' # append...
10
4024
by: Michael B Allen | last post by:
I have some code: *str++ = tolower(*str); that gcc is complaining about: warning: operation on `str' may be undefined I'm getting similar warnings for 'di' and 'bi' in:
1
5786
by: Digitek | last post by:
Hello, I have a big problem to print an html file directly to the printer. I use an "AxSHDocVw.AxWebBrowser" object. Briefly, this is my code: AxSHDocVw.AxWebBrowser myBrowser; .... //this set of instruction prepare my document in html to be printed string HtmlFileName = "Test.html"; Object o = new Object(); o =...
12
3022
by: Matthew Wilson | last post by:
Hi, we are getting a lot of spam through our PHP Feedback form, and have set up a new field 'prove you're human', asking them to do some simple maths. What is the command for the PHP script itself, to say "this field must be equal to 9 or return the error page"? Thanks! Matt
2
2532
by: sauve mark | last post by:
exec sp_prepare
23
24525
by: ticfranca | last post by:
Hi, I'm getting this error in the code below: sub Pega_recorde { $database = 'bundinha'; $host = 'localhost'; $usuario = 'myhumoradm'; $senha = 'my8xr2d2'; $dbh=DBI->connect("DBI:mysql:database=$database;host=$host","$usuario","$senha") or die "Can't open DB: $!";
3
4375
by: risrikanth | last post by:
hi, When iam executing the perl code iam getting error like"can't call method"bind_param_inout" with out package or object reference .here iam send little bit code plz check and can you tell me the solution for this $stmt = "BEGIN pr_tip_ia_emp(:1); END;"; $sth = $dbh->prepare($stmt) or &interface_error("Prepare Failed for $stmt....
11
14507
by: gautamga | last post by:
Hi All i have created the script which calls method from other script lib and while executing i get and error Can't call method "prepare" on an undefined value at /home/patriat/sourcescr/input/lib/patriat_lib.pl line 226. # conect to database $dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle'); ...
3
2464
by: Sagar | last post by:
Hi. I am working on a project to migrate a web application from 1.1 to 2.0 Within in the DAL of the application, there is a call to below function that builds a command object for later use. Inside this function iam getting a runtime error when the command object calls the prepare method.
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.