Re: DBD::Pg - question on using LIKE operator with bind variable

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: DBD::Pg - question on using LIKE operator with bind variable
Date: 2011-07-05 14:31:51
Message-ID: d7e283d0e41eef8e2dd5981b5850b627@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)turnstep(dot)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-----

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Francisco Figueiredo Jr. 2011-09-29 03:33:11 Npgsql 2.0.12 beta 2 released
Previous Message Miguel Garc&#xED;a 2011-07-05 00:07:00