Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl and MYSQL insert/update using quote 3

Status
Not open for further replies.

bneese

Technical User
Nov 16, 2003
20
US
I have a Perl script that is running a WMI query against a PC and then populating a MYSQL DB. The problem is that if the returned result has a quote in it like "Daemon's Home" it fails when it goes to do the insert. Here is a sample of my code:
-----------------------------------------------------------
foreach my $PRINFO ( in( $WMIServices->InstancesOf( $WIN32_PR ) ) )
{
$PRNUM = ++$PRNUMCount;
$sth = $db->prepare("UPDATE win32_product set
Vendor='PRINFO->{Vendor}'
WHERE PCID = $PCID AND PRNUM = $PRNUM");
$sth->execute();
}
-----------------------------------------------------------
First, is this a Perl issue or MYSQL issue. I believe it is a MYSQL issue but I can't figure out how to get by this. 'PRINFO->{Vendor} brings back Daemon's Home but then fails in the update. Here is the error:

-----------------------------------------------------------
DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S HOME'
-----------------------------------------------------------
 
Code:
use strict;
use warnings;
It's standard. You might not like the strict, as it forces you to declare every variable with my, but it is good practice. But you should always run with warnings on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top