473,503 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ 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 1523
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
6736
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
6040
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
2407
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
13629
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
10941
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
865
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
1479
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
971
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
1870
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...
0
7202
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
7328
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
7458
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...
0
5578
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,...
1
5013
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...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
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
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.