agora inbox for pgsql-interfaces@postgresql.org
help / color / mirror / Atom feedDBD::Pg - question on using LIKE operator with bind variable
2+ messages / 2 participants
[nested] [flat]
* DBD::Pg - question on using LIKE operator with bind variable
@ 2011-07-04 13:29 Max Pyziur <pyz@brama.com>
0 siblings, 1 reply; 2+ messages in thread
From: Max Pyziur @ 2011-07-04 13:29 UTC (permalink / raw)
To: pgsql-interfaces
Greetings,
I would like to use a bind variable with a LIKE operator.
An example of the query that I'm trying to use is the following:
SELECT ? , aa.f1, aa.f2, aa.f3, aa.f4 FROM orgs aa WHERE aa.f1 LIKE '%?%'
How do I get the conditional part of the query (WHERE aa.f1 LIKE '%?%') to
accept a bind variable?
Much thanks for your help.
Max Pyziur
pyz@brama.com
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: DBD::Pg - question on using LIKE operator with bind variable
@ 2011-07-05 14:31 Greg Sabino Mullane <greg@turnstep.com>
parent: Max Pyziur <pyz@brama.com>
0 siblings, 0 replies; 2+ messages in thread
From: Greg Sabino Mullane @ 2011-07-05 14:31 UTC (permalink / raw)
To: pgsql-interfaces
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
> I would like to use a bind variable with a LIKE operator.
>
> An example of the query that I'm trying to use is the following:
> SELECT ? , aa.f1, aa.f2, aa.f3, aa.f4 FROM orgs aa WHERE aa.f1 LIKE '%?%'
> How do I get the conditional part of the query (WHERE aa.f1 LIKE '%?%') to
> accept a bind variable?
(What did you try? What did you get?)
It's not clear why you have a question mark in the SELECT clause, but
you can solve the WHERE clause part by making the placeholder cover
the entire condition, rather than try to pass in only part of it
via the arguments. So try this instead:
$SQL = 'SELECT relname FROM pg_class WHERE relname LIKE ?';
$sth = $dbh->prepare($SQL);
$count = $sth->execute('%a%');
print "Count is $count\n";
- --
Greg Sabino Mullane greg@turnstep.com
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 201107051030
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iEYEAREDAAYFAk4TIEIACgkQvJuQZxSWSsgLCQCgtD6CdcTr8mpKeoBzYtaKtPjH
tfgAnA68obgfGN5dcORG4rZfqvejjkkC
=QZaM
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2011-07-05 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-07-04 13:29 DBD::Pg - question on using LIKE operator with bind variable Max Pyziur <pyz@brama.com>
2011-07-05 14:31 ` Greg Sabino Mullane <greg@turnstep.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox