WG: perl-plain Digest 16 Feb 2004 23:30:05 -0000 Issue 472

WG: perl-plain Digest 16 Feb 2004 23:30:05 -0000 Issue 472

am 17.02.2004 09:03:54 von mysql

Sure you'll get into trouble with this:
my $sth =3D $dbh->prepare("SELECT Date FROM links where Pkey =3D "2"); #
wrong=20

These two examples should work:
my $sth =3D $dbh->prepare("SELECT Date FROM links where Pkey =3D '2'");
#right

my $sth =3D $dbh->prepare(qq{SELECT Date FROM links where Pkey =3D =
"2"});#
right

HTH

Babs


-----Ursprüngliche Nachricht-----
Von: perl-plain-digest-help@lists.mysql.com
[mailto:perl-plain-digest-help@lists.mysql.com]=20
Gesendet: Dienstag, 17. Februar 2004 00:30
An: perl-plain@lists.mysql.com
Betreff: perl-plain Digest 16 Feb 2004 23:30:05 -0000 Issue 472

perl-plain Digest 16 Feb 2004 23:30:05 -0000 Issue 472

Topics (messages 2718 through 2719):

DBD::mysql - Setting a SELECT result set to a Scalar
2718 by: Nick Thomson
2719 by: Rudy Lippan

Administrivia:

To subscribe to the digest, e-mail:


To unsubscribe from the digest, e-mail:


To post to the list, e-mail:



------------------------------------------------------------ ----------
Date: Mon, 16 Feb 2004 10:34:41 -0800
To:
From: "Nick Thomson"
Subject: DBD::mysql - Setting a SELECT result set to a Scalar
Message-ID: <000601c3f4bb$8b05ca20$4c26fea9@lycedium>

Hi there mysql community! Based on the subject line of this e-mail, I
imagine it is quite evident that I am a newbie when it comes to
DBD::mysql. I'm using the Perl Mod: DBD::mysql and the script below is
a customization of a script I pulled off of the mod's doc found at:

http://search.cpan.org/~rudy/DBD-mysql-2.9003/lib/DBD/mysql. pm

Basically, my goal is to connect to my DB (profit_test), run the
following query: SELECT Date FROM links where Pkey =3D "2"; and set the
result set of the query to a scalar... all within a perl program.

I looked over the man page at the URL mentioned above to come up with
the following script:

=20
#!/usr/bin/perl

use DBI();

# Connect to the database.
my $dbh =3D
DBI->connect("DBI:mysql:database=3Dprofit_test;host=3Dlocalh ost",
"arrow", "head",
{'RaiseError' =3D> 1});

my $sth =3D $dbh->prepare("SELECT Date FROM links where Pkey =3D "2");
$sth->execute();
while (my $ref =3D $sth->fetchrow_hashref()) {
print "Found a row: id =3D $ref->{'Date'}, name =3D =
$ref->{'links'}\n";
} =20
print $sth;
print $dbh;

$sth->finish();=20

After running this script, I run into the following error message:

Number found where operator expected at sql1.pl line 10, near ""SELECT
Date FROM links where Pkey =3D "2"
(Missing operator before 2?)
String found where operator expected at sql1.pl line 13, near "print ""
(Might be a runaway multi-line "" string starting on line 10)
(Missing semicolon on previous line?)
Bareword found where operator expected at sql1.pl line 13, near "print
"Found"
(Do you need to predeclare print?)
syntax error at sql1.pl line 10, near ""SELECT Date FROM links where
Pkey =3D "2"
Execution of sql1.pl aborted due to compilation errors.

As mentioned earlier, all I really want to accomplish is to run the
following query: SELECT Date FROM links where Pkey =3D "2"; and set the
result set of the query to a scalar. I am using a mySQL database, is
DBD::mysql the wrong Mod to accomplish this? Is there an easier method
that I am unaware of? =20

Any assistance with regards to setting a SELECT result set to a Scalar
would be greatly appreciated!

Thanks in advance,

-Nick

------------------------------

Date: Mon, 16 Feb 2004 13:49:57 -0500 (EST)
To: Nick Thomson
From: Rudy Lippan
cc: msql-mysql-modules@lists.mysql.com
Subject: Re: DBD::mysql - Setting a SELECT result set to a Scalar
Message-ID:


On Mon, 16 Feb 2004, Nick Thomson wrote:

> #!/usr/bin/perl
>=20
> use DBI();
>=20
> # Connect to the database.
> my $dbh =3D
> DBI->connect("DBI:mysql:database=3Dprofit_test;host=3Dlocalh ost",
> "arrow", "head",
> {'RaiseError' =3D> 1});
>=20
> my $sth =3D $dbh->prepare("SELECT Date FROM links where Pkey =3D =
"2");
^^ ^^^^^^=20

You have a syntax error here. Just as a suggestion, you might want to
look
into q and qq when quoting data that contains quotes.

$dbh->prepare(q{SELECT Date FROM links WHERE Pkey =3D '2'});

Rudy

------------------------------

End of perl-plain Digest
***********************************



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