473,464 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fetching values in Perl

2 New Member
Hi all,
I have written a query like this.
----------------------------------------------------------

$dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostnam e", "$username", "$password");

$statement = "SELECT patient_intime from $table_name where patient_intime=$ARGV[0])";


----------------------------------------------------------
I want all the "patient_intime" values to be retreived, where there are other columns(fields) also.
Pls suggest me how to proceed.

Thanks in advance.
Padmaja T N.
Sep 28 '07 #1
2 1521
numberwhun
3,509 Recognized Expert Moderator Specialist
Hi all,
I have written a query like this.
----------------------------------------------------------

$dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostnam e", "$username", "$password");

$statement = "SELECT patient_intime from $table_name where patient_intime=$ARGV[0])";


----------------------------------------------------------
I want all the "patient_intime" values to be retreived, where there are other columns(fields) also.
Pls suggest me how to proceed.

Thanks in advance.
Padmaja T N.
Well, you will find that a lot of people use the common practice of doing a "prepare()" function to get the statement ready and then issue the execute() function to execute it and get the data from the database.

To get an idea of how to work with DBI, you will definitely want to check out the DBI module on CPAN as its documentation is filled with examples to help you get going.

Regards,

Jeff
Sep 28 '07 #2
eWish
971 Recognized Expert Contributor
Here is what I use.

Expand|Select|Wrap|Line Numbers
  1. my $data_source = 'DBI:mysql:' . $mysql_database_name . ':' . $mysql_server_name;
  2. my $dbh = DBI->connect( $data_source, $mysql_user_name, $mysql_password, {PrintError=>1}) ||  die "$DBI::errstr"; 
  3.  
  4. my $value = $ARGV[0];
  5.  
  6. my $sleect_statement = $dbh->prepare('SELECT  patient_intime  FROM $table_name WHERE patient_intime=?');
  7.    $select_statement->execute($value);
The '?' is called a placeholder. The DBI will escape special characters for you in when placeholders are used. You can also use $select_statement->quote($value);. Just more typing, I would read the docs that numberwhun mentioned, or even pick up the book 'Perl DBI' if you plan on doing much database work.
Sep 29 '07 #3

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

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
3
by: Daves | last post by:
trying to get a boolean value from DataReader (that is, result from a SQL query); boolean MyBool = MyDataReader.GetBoolean(3); well it works using that number 3 but of course I would like to...
1
by: orfeas | last post by:
Hi! I am new here so pardon me for my naivity! I have written this code for grabbing the text(only the text) for a URL(e.g www.msn.com) with Perl: use LWP:: UserAgent; use...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
16
by: Preben Randhol | last post by:
Hi A short newbie question. I would like to extract some values from a given text file directly into python variables. Can this be done simply by either standard library or other libraries? Some...
0
by: idorjee | last post by:
hi guys, here is what i've been trying to do. i have two arrays (@arr1 and @arr2) which i compare and get the difference in them, which work fine. but now i'm trying to get the info (ie, the id of...
2
by: padmaja3 | last post by:
Hi all, I have written a query like this. ---------------------------------------------------------- $dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); ...
1
shrek123
by: shrek123 | last post by:
Hi, I want to execute some script (May or May not be perl script) from a perl script and print the output of that executed script. My Operating system are Windows and Mac OS(Unix). I was trying...
2
by: anusha.vempati9 | last post by:
Hi All, I am calling a cgi file from a perl module. The cgi file contains the HTML form and some HTML fields(like check boxes). In my logic, I am trying to submit the form and calling the same...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.