bendon has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have been trying to make this code work for days but failed.
This is the CGI code reciving the XML from a client.
I would like to insert the messageId and text to MySql DB.
#!/usr/bin/perl -w use strict; use Time::Piece; use warnings FATAL => 'all'; use CGI qw(); use POSIX qw/strftime/; use LWP::UserAgent; use HTTP::Request; use XML::Simple; use SOAP::WSDL; use SOAP::WSDL::Deserializer::Hash; use SOAP::Lite; use Time::Piece; use XML::LibXML; use XML::Twig; use Data::Dumper; use DBI; my $cgi = CGI->new; print $cgi->header(-type => "text/xml", -charset => "utf-8"); my $xml = $cgi->param("POSTDATA"); my $dbh = DBI->connect("DBI:mysql:smscenter", "smscenter", "smsc1234", +{ RaiseError => 1, AutoCommit => 1 }); $dbh->trace(2); my $sql1 = 'INSERT INTO test(test,test1) VALUES(?,?)'; my $sth1 = $dbh->prepare($sql1); my $twig = new XML::Twig( twig_handlers => { ServiceException => \&ServiceException, } ); $twig->parse($xml); sub ServiceException { my ( $twig, $ServiceException ) = @_; my @f = ( $ServiceException->field('messageId'), $ServiceException->field('text'), ); print $f[0], "\n"; print $f[1], "\n"; $sth1->execute( @f ) or die $DBI::errstr; }
The XML being sent is this
<?xml version=\"1.0\" encoding=\"utf-8\"?> <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/enve +lope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> <soapenv:Body> <soapenv:Fault> <faultcode>SVC0008</faultcode> <faultstring>Duplicate SMS notification, criteria is default criteria, + centralCode is 20245</faultstring> <detail> <ns1:ServiceException xmlns:ns1=\"http://www.csapi.org/schema/parlayx/ +common/v2_1\"> <messageId>SVC0008</messageId> <text>Duplicate SMS notification, criteria is default criteria, centra +lCode is 20245</text> <variables>default criteria</variables> <variables>20245</variables> </ns1:ServiceException> </detail> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>
Where am I going wrong.
Really need your assistance.
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI Server Insert XML Data to Mysql
by poj (Abbot) on Oct 23, 2014 at 07:25 UTC | |
|
Re: CGI Server Insert XML Data to Mysql
by GotToBTru (Prior) on Oct 22, 2014 at 21:38 UTC | |
by bendon (Novice) on Oct 23, 2014 at 09:49 UTC |