Generally, people use q{} and qq{} quotation notation to avoid having to
concatenate, and to avoid the interference of quotes required by the SQL
statement - or other statements. The problem in the original question was
that the person used a single q with the q{} quote notation. A single q
works like a single quote, so the statement is not parsed for variables.
qq{} (double q's) works like double quote marks in that the contents are
parsed for variables, but it is usually better in situations like this than
the " double quotes because it can contain single or double quotes within it
without needing a concatenation. That was the first suggestion. Just change
the q{} notation to a qq{} quote notation, and $addr will be replaced within
it with the value of $addr before the statement is prepared.

Steve H.

-----Original Message-----
From: Hugh J. Hitchcock [mailto:[EMAIL PROTECTED]]
Sent: Sunday, August 12, 2001 7:35 PM
To: [EMAIL PROTECTED]
Subject: RE: Cannot Insert into SQL Server


probably the placehoder answer would work. But other than that, I think this
would probably work:

   my $sth = $dbh->prepare("insert into emails values ('$addr')")
            || die "Can't prepare statement: $DBI::errstr";

embedding the value inside of double quotes or

  my $sth = $dbh->prepare("insert into emails values ('" . $addr . "')")
            || die "Can't prepare statement: $DBI::errstr";

quoting the string with double qoutes and concatentating the single quotes
with the value contained in $addr, resulting in the correct statement...
more of a perl problem than a DBI problem.

Hope this helps.

H

> -----Original Message-----
> From: nayeem [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, August 12, 2001 11:26 AM
> To: [EMAIL PROTECTED]
> Subject: Cannot Insert into SQL Server
>
>
> Can Anybody help me to insert the records in Sql Server.
> Actually this code
> is working but inserting $addr as value instead of variable $addr
> 's  value
> that is abc, so is there any solution to add the variable values...
>
> use DBI;
> my $addr ='abc';
> my $dbh = DBI->connect("dbi:ODBC:email", "sa", "zajilpass")
>       || die "Can't connect to $data_source: $DBI::errstr";
>   my $sth = $dbh->prepare( q{
>           insert into emails values ('$addr')
>   }) || die "Can't prepare statement: $DBI::errstr";
>   my $rc = $sth->execute
>       || die "Can't execute statement: $DBI::errstr";
>
>
> check this code and please advice me.
>
> Thanks,
> Nayeem.
>
>
>
>

Reply via email to