Hi,

> The statement I'm using is the following:
>
> $sql_statement = "INSERT INTO rxPkt VALUES(\'$nodeId\', \'$rxNetTime\',
> \'$rxLat\', \'$rxLon\', \'$rxHeading\', \'$antIndex\', \'$rxPower\',
> \'$bin_msg\')";

The best way to do this is use placeholders.  In your example above, if any
of the variables contains double quotes perl may interpret that as end of
the string (and thus you'll have incorrect SQL statement).  If variable
contains single quote, MySQL will interpret that incorrectly.

Please try the following:

$dbh->do(q{ INSERT INTO rxPkt VALUES (?, ?, ?, ?, ?, ?, ?, ?) }, undef,
               $nodeId, $rxNetTime, $rxLat, $rxLon, $rxHeading, $antIndex,
$rxPower, $bin_msg
              );

This is equivalent to:
$sth = $dbh->prepare(q{ INSERT INTO rxPkt VALUES (?, ?, ?, ?, ?, ?, ?,
?) });
$sth->execute($nodeId, $rxNetTime, $rxLat, $rxLon, $rxHeading, $antIndex,
$rxPower, $bin_msg);

Using placeholders is a common practice.  It makes code more readable and
helps you avoid errors.

For more information on using placeholders, read "perldoc DBI".

Regards,
Alex.

Reply via email to