Advertisement
Guest User

Untitled

a guest
Oct 25th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. <?php
  2. $conn = null;
  3.  
  4. try
  5. {
  6. $dbhost = "localhost";
  7. $user = "root";
  8. $pass = "vicidialnow";
  9. $dbname = "asterisk";
  10.  
  11. $conn = new mysqli($dbhost, $user, $pass, $dbname);
  12. $conn->set_charset('utf8');
  13. }
  14. catch(mysqli_sql_exception $e)
  15. {
  16. echo $e->getMessage();
  17. echo $e->getTraceAsString();
  18. }
  19.  
  20. try
  21. {
  22.  
  23. $queryS = $conn->stmt_init();
  24. $queryS->prepare("SELECT *
  25. FROM vicidial_list
  26. WHERE list_id = 1240 AND status LIKE 'INT' AND (
  27. (phone_number NOT LIKE '' AND phone_number NOT IN (
  28. SELECT phone_number
  29. FROM vicidial_list
  30. WHERE list_id = 1241 AND phone_number NOT LIKE ''
  31. )) OR (phone_number NOT LIKE '' AND alt_phone NOT IN (
  32. SELECT alt_phone
  33. FROM vicidial_list
  34. WHERE list_id = 1241 AND alt_phone NOT LIKE ''
  35. ))
  36. )"
  37. );
  38. $queryS->execute();
  39. $queryS->store_result();
  40. $queryS->bind_result($lead_id, $entry_date, $modify_date, $status, $user, $vendor_lead_code, $source_id, $list_id,
  41. $gmt_offset_now, $called_since_last_reset, $phone_code, $phone_number, $title, $first_name, $middle_initial, $last_name,
  42. $address1, $address2, $address3, $city, $state, $province, $postal_code, $country_code, $gender, $date_of_birth, $alt_phone, $email,
  43. $security_phrase, $comments, $called_count, $last_local_call_time, $rank, $owner, $entry_list_id);
  44.  
  45. $insertList = "INSERT INTO vicidial_list (entry_date, modify_date, status, user, vendor_lead_code, source_id, list_id,
  46. gmt_offset_now, called_since_last_reset, phone_code, phone_number, title, first_name, middle_initial, last_name,
  47. address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email,
  48. security_phrase, comments, called_count, last_local_call_time, rank, owner, entry_list_id)
  49. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  50. $insertCustom = "INSERT INTO custom_1241 (lead_id, nome, indirizzo, codice_fiscale, data_nascita, residenza, operazione_in_corso,
  51. durata, datore_lavoro, decorrenza, altre_trattenute, rata, seconda_trattenuta, commenti)
  52. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  53. $conn->autocommit(false);
  54.  
  55. $count = 0;
  56. $inTransaction = false;
  57. $listId = 1241;
  58.  
  59. while($queryS->fetch())
  60. {
  61. if($count == 0)
  62. {
  63. if($inTransaction)
  64. {
  65. $conn->commit();
  66. $inTransaction = false;
  67. }
  68. $inTransaction = true;
  69. }
  70.  
  71. $queryI1 = $conn->stmt_init();
  72. $queryI1->prepare("INSERT INTO vicidial_list (entry_date, modify_date, status, user, vendor_lead_code, source_id, list_id,
  73. gmt_offset_now, called_since_last_reset, phone_code, phone_number, title, first_name, middle_initial, last_name,
  74. address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email,
  75. security_phrase, comments, called_count, last_local_call_time, rank, owner, entry_list_id)
  76. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  77.  
  78. $queryI1->bind_param("ssssssssssssssssssssssssssssssssss",
  79. $entry_date, $modify_date, $status, $user, $vendor_lead_code, $source_id, $listId,
  80. $gmt_offset_now, $called_since_last_reset, $phone_code, $phone_number, $title, $first_name,
  81. $middle_initial, $last_name, $address1, $address2, $address3, $city, $state, $province, $postal_code,
  82. $country_code, $gender, $date_of_birth, $alt_phone, $email, $security_phrase, $comments,
  83. $called_count, $last_local_call_time, $rank, $owner, $entry_list_id);
  84. $queryI1->execute();
  85. $new_lead_id = $queryI1->insert_id;
  86. $queryI1->close();
  87.  
  88. $queryS2 = $conn->stmt_init();
  89. $queryS2->prepare("SELECT * FROM custom_1240 WHERE lead_id = ?");
  90. $queryS2->bind_param("s", $lead_id);
  91. $queryS2->execute();
  92. $queryS2->store_result();
  93. $queryS2->bind_result($lead_id_2, $nome, $indirizzo, $codice_fiscale, $data_nascita, $residenza, $operazione_in_corso,
  94. $durata, $datore_lavoro, $decorrenza, $altre_trattenute, $rata, $seconda_trattenuta, $commenti);
  95.  
  96.  
  97. if($queryS2->fetch())
  98. {
  99. $queryI2 = $conn->stmt_init();
  100. $queryI2->prepare("INSERT INTO custom_1241 (lead_id, nome, indirizzo, codice_fiscale, data_nascita, residenza, operazione_in_corso,
  101. durata, datore_lavoro, decorrenza, altre_trattenute, rata, seconda_trattenuta, commenti)
  102. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  103. $queryI2->bind_param("ssssssssssssss", $new_lead_id, $nome, $indirizzo, $codice_fiscale, $data_nascita,
  104. $residenza, $operazione_in_corso, $durata, $datore_lavoro, $decorrenza, $altre_trattenute,
  105. $rata, $seconda_trattenuta, $commenti);
  106. $queryI2->execute();
  107. $queryI2->close();
  108. }
  109. $queryS2->free_result();
  110. $queryS2->close();
  111.  
  112. $count++;
  113. if($count == 100)
  114. {
  115. if($inTransaction)
  116. {
  117. $conn->commit();
  118. $inTransaction = false;
  119. }
  120. $count = 0;
  121. }
  122. }
  123. if($inTransaction)
  124. $conn->commit();
  125. $inTransaction = false;
  126.  
  127. $queryS->free_result();
  128. $queryS->close();
  129. }
  130. catch(mysqli_sql_exception $e)
  131. {
  132. if($inTransaction)
  133. $conn->rollback();
  134.  
  135. echo $e->getMessage();
  136. echo $e->getTraceAsString();
  137. }
  138.  
  139. $conn->close();
  140. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement