Perl-SQLite3: main question

I admit that some time has passed since I used Perl, but it puzzled me.

Here's the problem:

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use DBI;

print "Content-type: text/html\n\n";
print "<html><head><title></title></head></body>";

my $login = "admin@xxxxx.com";
my $dbfile = "/var/www/shopsite-data/shopsite_db";
my $sql = qq`SELECT ss_OrderID FROM ss_ORDER WHERE ss_Email=?`;

my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "") || die "Cannot connect: $DBI::errstr";

my $sth = $dbh->prepare($sql);
$sth->execute($login) or die $sth->errstr();
while (my @result = $sth->fetchrow_array()) {
  print "OrderID: $result[0]<br />";
}
$sth->finish;

print "</body>";
print "</html>";
$dbh->disconnect;

returns nothing, but I get a result set when I log in with sqlite3 using the same query. I also get a result set when changing a query from

my $sql = qq`SELECT ss_OrderID FROM ss_ORDER WHERE ss_Email=?`;

to

my $sql = qq`SELECT ss_OrderID FROM ss_ORDER`;
+3
source share
2 answers

The obvious problem is @ inside double quotes:

my $login = "admin@xxxxx.com";

probably comes out like

 $login = "admin.com"

, , Perl @xxxx , , . , @xxxx. , .

, , @xxxx :

my $login = 'admin@xxxxx.com';

my $login = "admin\@xxxxx.com";

@. script, .

Perl.

...

: fatalsToBrowser,

use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

, , warningsToBrowser, script ( ) (), - .

+13

, Kinopiko .

, CGI.pm, . CGI::header.

:

print "<html><head><title></title></head></body>";

body, .

, ,

use strict;
use warnings;

.

+4

Source: https://habr.com/ru/post/1723175/


All Articles