Any Perl DBI experts?

Matt Shields matt-urrlRJtNKRMsHrnhXWJB8w at public.gmane.org
Wed Oct 14 08:59:18 EDT 2009


On Wed, Oct 14, 2009 at 8:54 AM, David Hummel <lemmuh-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:

> On Wed, Oct 14, 2009 at 7:52 AM, Matt Shields <matt-urrlRJtNKRMsHrnhXWJB8w at public.gmane.org>
> wrote:
> > I'm using DBI to query a MySQL database and I've used the following in
> > numerous scripts I've written.  In every previous case I knew there was
> data
> > in the resultset, but this time there may or may not be data.  If there
> > isn't data, I get an error with the bind_columns statement.  How can I
> test
> > to see there are results before doing the bind_columns and while?
> >
> > $sql = "SELECT id, name FROM table";
> > $query = $dbh->prepare(qq{ $sql }) or die "Can't prepare SQL statement:
> > $dbh::errstr\n";
> > $query->execute or die "Can't execute SQL statement: $dbh::errstr\n";
> >
> > $query->bind_columns(\$id,\$name);
> >
> > while ($query->fetch) {
> >  print "$id - $name\n";
> > }
>
> This shouldn't be causing an error.  bind_columns (and bind_col)
> doesn't care if data is returned by the SELECT, although in rare cases
> there can be issues with data types.
>
> Please provide the error output via:
>
> $query->bind_columns(\$id,\$name) or die "Can't bind columns:
> $dbh::errstr\n";
>
> What are the data types for the "id" and "name" columns?  What
> versions of Perl, DBI, DBD::mysql, and MySQL are you using?
>

Ah ha!!! I found the error, it just took me reading the error message. :)  I
was making numerous edits to the actual SQL statement and added a field, but
forgot to add it to the bind_columns statement.

DBD::mysql::st bind_columns failed: bind_columns called with 3 values but 4
are needed at ./check.pl line 61.

-matt
http://www.sysadminvalley.com
http://www.beantownhost.com
http://www.linkedin.com/in/mattboston
Stephen Leacock<http://www.brainyquote.com/quotes/authors/s/stephen_leacock.html>
- "I detest life-insurance agents: they always argue that I shall some
day
die, which is not so."





More information about the Discuss mailing list