<?php
$y = base64_encode(serialize($x[chan_vars]));

$query = "
INSERT INTO `cdr`
  (`id`, `billed`, `clid`, `src`, `dst`, `dcontext`, `channel`, `dstchannel`, `lastapp`, `lastdata`, `duration`,
  `billsec`, `disposition`, `amflags`, `accountcode`, `start`, `answer`, `end`, `flags`, `unigueid`, `userfield`, `chan_vars`)
VALUES
  ('', '', '$x[clid]', '$x[src]', '$x[dst]', '$x[dcontext]', '$x[channel]', '$x[dstchannel]', '$x[lastapp]', '$x[lastdata]', '$x[duration]',
  '$x[billsec]', '$x[disposition]', '$x[amflags]', '$x[accountcode]', '$x[start]', '$x[answer]', '$x[end]', '$x[flags]', '$x[uniqueid]', '$x[userfield]', '$y')
";

$link = mysql_connect('localhost', 'username', 'password')
   or die('Could not connect: ' . mysql_error());
mysql_select_db('asterisk') or die('Could not select database');

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($link);
?>