Gossamer Forum
Home : General : Databases and SQL :

DBI $sth->{NAME_lc} with INNER JOIN

Quote Reply
DBI $sth->{NAME_lc} with INNER JOIN
I'm having trouble with some code that I copied from perldoc. The code is supposed to create a hash of the current record with the filenames as keys. Here's the relevant portion:

====

$dbh = DBI->connect('dbi:ODBC:GTDB', '', '');
$sth = $dbh->prepare("SELECT * FROM Contacts INNER JOIN ON (Contacts.Responsible = Users.UserID) WHERE ID = ?");
$sth->execute(param(ID));
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
$sth->fetch;
====

The code works perfectly without the inner join clause in the SQL statement, but as soon as I add the INNER JOIN Clause I get:

"Describe failed during DBI::st=HASH(0xe7e96c)->FETCH(NAME) at E:/Apache2/perl/GT/contact_view.pl line 32."

Any help would be greatly appreciated, I'm not relishing having to refer to the fields by numbers instead of names.

Thanks in advance!

Andrew
Quote Reply
Re: [amrodgers] DBI $sth->{NAME_lc} with INNER JOIN In reply to
You missed 'Users' in the SQL command:

$sth = $dbh->prepare("SELECT * FROM Contacts, Users INNER JOIN ON (Contacts.Responsible = Users.UserID) WHERE ID = ?");

TheStone.

B.
Quote Reply
Re: [TheStone] DBI $sth->{NAME_lc} with INNER JOIN In reply to
Thanks, I fixed that, but the error is the same.
Quote Reply
Re: [amrodgers] DBI $sth->{NAME_lc} with INNER JOIN In reply to
Oops, my bad. corrected the SQl statmept to:

SELECT * FROM Contacts INNER JOIN Users ON (Contacts.Responsible = Users.UserID) WHERE ID = ?

I guess my SQL is rustier than I thought. Thanks for the help!
Quote Reply
Re: [amrodgers] DBI $sth->{NAME_lc} with INNER JOIN In reply to
http://www.mysql.com/doc/en/JOIN.html

Wink