<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi,<br>
<br>
I need a little help. I am trying to use example for inserting XML
to mysql cdrtable. I have add id before caller_id_name as I need Id
in mysql table. Problem is that I am getting random numbers in ID
field, sometimes values for ID are the same, so sql perl script
return error and values are not inserted.<br>
<br>
Can you help me how can I modify so that this will work properly.<br>
<br>
<small>use strict;<br>
use warnings;<br>
use CGI;<br>
use DBI;<br>
use Data::Dump qw(dump);<br>
$|++;<br>
my $q = CGI->new;<br>
my $raw_cdr = $q->param('cdr');<br>
<br>
my @all_fields = qw(id caller_id_name caller_id_number<br>
destination_number context start_stamp answer_stamp end_stamp<br>
duration billsec hangup_cause uuid bleg_uuid<br>
accountcode domain_name);<br>
my @fields;<br>
my @values;<br>
foreach my $field (@all_fields) {<br>
next unless $raw_cdr =~ m/$field>(.*?)</;<br>
push @fields, $field;<br>
push @values, "'" . urldecode($1) . "'";<br>
}<br>
my $cdr_line;<br>
my $query = sprintf(<br>
"INSERT INTO %s (%s) VALUES (%s);",<br>
'radacct_1', join(',', @fields), join(',', @values)<br>
);<br>
my $db =
DBI->connect('DBI:mysql:dbname=voipbill_slo;host=xxx.xxx.xxx.xxx','xxxxxx',
'xxxxx');<br>
$db->do($query);<br>
print $q->header();<br>
sub urldecode {<br>
my $url = shift;<br>
$url =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;<br>
return $url;<br>
}<br>
[root@fs1 cgi-bin]# cat /var/log/secure</small><br>
<br>
Thank you!<br>
<br>
Regards,<br>
Miha<br>
</body>
</html>