I'm having a devil of a time trying to insert a Windows UNC share into my MySQL database. The DBI quote function doesn't seem to be behaving as I would expect. Here's a little example:

#!/usr/bin/perl -w
use DBI;
my $unc = '\\somebox.somehost.com\someshare';
my $dsn = "DBI:mysql:cmdb;localhost";
my $dbh = DBI->connect($dsn,'root','') or die;

my $quoted_unc = $dbh->quote($unc);
$dbh->do("INSERT INTO mytable (uncname) VALUE ($quoted_unc)");

When I run this code, and then run a select against mytable, my UNC share is not the same as it was when it went in:


If I double-quote the unc variable like this:

my $unc = "\\somebox.somehost.com\someshare";

The result is different, but not much better:


Anyone know how to get around this problem?

Hi KevinADC, thanks for the reply. As it turns out, the quote function was operating as expected. My problem was after the UNC was inserted, I was doing a select on that table and comparing the value that I inserted with the value that made it into the database, and I was doing the insert and comparison with 2 different methods:

To insert data:

$dbh->do("INSERT INTO table (uncname) VALUE ('$unc_name')");

To select data:

$sth = $dbh->prepare("SELECT uncname FROM table WHERE uncname = ?");

So, the select had the benefit of the quoting function, while the insert didn't. Thanks for the post!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.