Fetching values in Perl

Fetching values in Perl

am 28.09.2007 15:15:06 von padmaja

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

$dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$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.
--
View this message in context: http://www.nabble.com/Fetching-values-in-Perl-tf4534430.html #a12940280
Sent from the MySQL - Perl mailing list archive at Nabble.com.


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Fetching values in Perl

am 28.09.2007 15:20:53 von Baron Schwartz

Hi,

padmaja wrote:
> Hi all,
> I have written a query like this.
> ----------------------------------------------------------
>
> $dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$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.

Try this:

SELECT * FROM $table_name ....

SELECT * is not a good idea to just blindly write, though. In general
it's a much better idea to explicitly name the columns you know you need
(it's more efficient, you don't get any nasty surprises when someone
adds another column to the table, you will get an explicit error when
someone drops a column your application actually needs...)

Baron

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Fetching values in Perl

am 28.09.2007 15:33:03 von Eric Frazier

Baron Schwartz wrote:
> Hi,
>
> padmaja wrote:
>> Hi all,
>> I have written a query like this.
>> ----------------------------------------------------------
>>
>> $dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname",
>> "$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.
>
Sorry to reply to a reply, I didn't see the first post.

Are you saying you want to do SELECT patient_intime FROM $table_name
WHERE field1 IS NOT NULL AND field2 IS NOT NULL etcl.......

I am not really sure what the question is..

Eric

> Try this:
>
> SELECT * FROM $table_name ....
>
> SELECT * is not a good idea to just blindly write, though. In general
> it's a much better idea to explicitly name the columns you know you
> need (it's more efficient, you don't get any nasty surprises when
> someone adds another column to the table, you will get an explicit
> error when someone drops a column your application actually needs...)
>
> Baron
>


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Fetching values in Perl

am 28.09.2007 16:19:38 von Greg Meckes

Perhaps you could do it like this:

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

# Do some checking and untainting with $ARGV[0]
# I wouldn't just pass an argument like that
# directly to a query.

my $arg = $ARGV[0]; # Check it here

$statement = "SELECT patient_intime from $table_name where patient_intime=$arg)";

my $sth = $dbh->prepare($statement) or die "Couldn't execute statement: " . $sth->errstr;
$sth->execute;

my @data = ();

while (@data = $sth->fetchrow_array()) {
$patient_intime = $data[0];
}

--- padmaja wrote:

>
> Hi all,
> I have written a query like this.
> ----------------------------------------------------------
>
> $dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$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.
> --
> View this message in context:
> http://www.nabble.com/Fetching-values-in-Perl-tf4534430.html #a12940280
> Sent from the MySQL - Perl mailing list archive at Nabble.com.
>
>
> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>
>


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Fetching values in Perl

am 28.09.2007 18:05:21 von Patrick Galbraith

Greg Meckes wrote:

>Perhaps you could do it like this:
>
>$dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname",
> "$username",
>"$password");
>
># Do some checking and untainting with $ARGV[0]
># I wouldn't just pass an argument like that
># directly to a query.
>
>my $arg = $ARGV[0]; # Check it here
>
>$statement = "SELECT patient_intime from $table_name where patient_intime=$arg)";
>
>
I would add to this the suggestion of using placeholders as well (to
ensure proper quoting, inection issues)

$statement = "SELECT patient_intime from $table_name where patient_intime= ?";

>my $sth = $dbh->prepare($statement) or die "Couldn't execute statement: " . $sth->errstr;
>$sth->execute;
>
>
$sth->execute($arg);

>my @data = ();
>
>while (@data = $sth->fetchrow_array()) {
>$patient_intime = $data[0];
>}
>
>--- padmaja wrote:
>
>
>
>>Hi all,
>>I have written a query like this.
>>----------------------------------------------------------
>>
>>$dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$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.
>>--
>>View this message in context:
>>http://www.nabble.com/Fetching-values-in-Perl-tf4534430.ht ml#a12940280
>>Sent from the MySQL - Perl mailing list archive at Nabble.com.
>>
>>
>>--
>>MySQL Perl Mailing List
>>For list archives: http://lists.mysql.com/perl
>>To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>>
>>
>>
>>
>
>
>
>


--
Patrick Galbraith, Senior Programmer
Grazr - Easy feed grazing and sharing
http://www.grazr.com

Satyam Eva Jayate - Truth Alone Triumphs
Mundaka Upanishad




--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org