Advertisement
dlucio

Archive 2

Jan 10th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. $mysqli = new mysqli('localhost', 'root', '', 'fusionpbx');
  4.  
  5. if ($mysqli->connect_errno) {
  6.         print 'Error: '.$mysqli->connect_error.PHP_EOL;
  7.         exit (1);
  8. }
  9.  
  10. $mysqli_archive = new mysqli('voiply.mysql.database.azure.com', 'voipadmin@voiply', 'V01Padmin2016', 'fusionpbx');
  11.  
  12. if ($mysqli_archive->connect_errno) {
  13.         print 'Error 2: '.$mysqli_archive->connect_error.PHP_EOL;
  14.         exit (1);
  15. }
  16.  
  17. $sql = 'SELECT * FROM v_xml_cdr WHERE answer_stamp < DATE_SUB(NOW(), INTERVAL 30 DAY) limit 1';
  18. if ($result = $mysqli->query($sql)){
  19.  
  20.         while ($row = $result->fetch_assoc()){
  21.                 $cols = implode(',', array_keys($row));
  22.                 foreach (array_values($row) as $value){
  23.                         isset($vals) ? $vals .= ',' : $vals = '';
  24.                         $vals .= '\''.$mysqli_archive->real_escape_string($value).'\'';
  25.                 }
  26.                 $sql_archive = 'INSERT INTO v_xml_cdr ('.$cols.') VALUES ('.$vals.')';
  27.                 echo $sql_archive;
  28.                 $mysqli_archive->query($sql_archive);
  29.         }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement