Re: [DBI] Re: What is wrong with select?

2005-04-03 Thread Steven Lembark

Basicly $StateProvince in a string value in you sql statement, so you
either single quote yourself, or let DBI do it.
Or use a placeholder and save yourself the pain of figuring
it out:
   select ...  where name_short = ?
will do the deed without your having to even think
about quoting.
--
Steven Lembark   85-09 90th Street
Workhorse ComputingWoodhaven, NY 11421
[EMAIL PROTECTED] 1 888 359 3508


Re: [DBI] Re: What is wrong with select?

2005-04-02 Thread Dave Cash
On Sat, 2 Apr 2005, Juan Jose Natera wrote:

 Hi,

  It works. But when I do:
 
  $StateProvince = 'PA';
  my $sql1 = SELECT id, name_short, name_long FROM states WHERE
  name_short=$StateProvince;
  $sth1 = $dbh-prepare($sql1);
  #
  $sth1-execute();
 
  I get a message that:
 
  DBD::mysql::st execute failed: Unknown column 'PA' in 'where clause' at
  TestDBI.pl line 14.

 try this:

 $StateProvince = q/'PA'/;
 my $sql1 = SELECT id, name_short, name_long FROM states WHERE
 name_short=$StateProvince;

 or better yet:

 $StateProvince = q/'PA'/;

For this version, I think you mean:

 $StateProvince = 'PA';

 my $sql = 'SELECT id, name_short, name_long FROM states WHERE name_short= ?';
 $sth = $dbh-prepare($sql);
 $sth-execute($StateProvince);

 Basicly $StateProvince in a string value in you sql statement, so you
 either single quote yourself, or let DBI do it.

 Regards,

 JJ