473,573 Members | 2,610 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');
  6. # sets variable $productID to a value of 1
  7. $productID=1;
  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);
  14. # Executes the SQL statement defined in query1
  15. $query_handle->execute();
Oct 30 '06 #1
2 12619
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.";
  5. # sets variable $productID to a value of 1
  6. $productID=1;
  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);
  13. # Executes the SQL statement defined in query1
  14. $query_handle->execute() or die $dbh->errstr;
Oct 30 '06 #2
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

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...
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:
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 =...
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
by: sauve mark | last post by:
exec sp_prepare
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: $!";
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....
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'); ...
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.
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. ...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
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...
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...
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
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.