Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the equivalent of escaping strings for MySQL database input in Perl?

Tags:

mysql

perl

What's the equivalent of escaping strings for MySql database input in perl?

Is Quote the best way?

like image 254
Dirk Avatar asked Dec 30 '22 18:12

Dirk


1 Answers

You can use DBI placeholders.

Here is an example (from this link):

#! /usr/bin/perl

use DBI;

print "Enter the city you live in: ";
chomp( $city = <STDIN> );
print "Enter the state you live in: ";
chomp( $state = <STDIN> );

$dbh = DBI->connect(your db info here);
$sth = $dbh->prepare( "SELECT name WHERE city = ? AND state = ?" );
$sth->execute( $city, $state );
like image 52
mechanical_meat Avatar answered Jan 02 '23 09:01

mechanical_meat