Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2. #Connection variables for MYSQL:
  3. $mysql_host = 'SERVER';
  4. $mysql_user = 'haldur';
  5. $mysql_password = 'PAROOL';
  6. $mysql_database = 'test';
  7. $mysql_link = new PDO(
  8. "mysql:host=$mysql_host;dbname=$mysql_database;charset=utf8",
  9. $mysql_user,
  10. $mysql_password
  11. );
  12.  
  13. #Connection variables for MSSSQL:
  14. $mssql_host = '213.168.13.18:1433';
  15. $mssql_user = 'VAATAJA';
  16. $mssql_password = 'PAROOL';
  17. $mssql_database = 'BAAS';
  18. $mssql_link = new PDO(
  19. "dblib:host=$mssql_host;dbname=$mssql_database",
  20. $mssql_user,
  21. $mssql_password
  22. );
  23.  
  24. $tables = array('TABEL'); # tabeli nimed siia
  25.  
  26. #SET CHARACTER SET to utf8:
  27. $mysql_link->prepare("SET NAMES 'utf8'")->execute();
  28. $mysql_link->prepare("SET CHARACTER SET 'utf8'")->execute();
  29.  
  30. #Migrate the data:
  31. foreach($tables as $table){
  32. $deleteQuery = "DELETE FROM $table";
  33. try{
  34. $mysql_link->prepare($deleteQuery)->execute();
  35. }
  36. catch (PDOException $e){
  37. echo $e->getMessage();
  38. }
  39. $mssql_selection = 'SELECT RTRIM(*) FROM ' .$table;
  40. $m_res = $mssql_link->prepare($mssql_selection);
  41. $m_res->execute();
  42.  
  43. $j = 0;
  44. $query = "";
  45. $sql = "";
  46. while( ($rec = $m_res->fetch(PDO::FETCH_NUM)) !== false) {
  47. $j = $j++;
  48. $cols = count($rec);
  49. for($i = 0; $i < $cols; $i++){
  50. if(is_string($rec[$i]))
  51. $rec[$i] = $mssql_link->quote($rec[$i]);
  52.  
  53. if(is_null($rec[$i]))
  54. $rec[$i] = 'NULL';
  55. }
  56. $query .= "(".implode(",", $rec)."),";
  57. }
  58. $sql = "INSERT INTO ".$table." VALUES ". $query;
  59. echo "<pre>",$table, ' >> ', $j, " kirjet
  60. ", $sql,"</pre>";
  61. try{
  62. $mysql_link->prepare($sql)->execute();
  63. }
  64. catch (PDOException $e)
  65. {
  66. echo $e->getMessage();
  67. }
  68. }
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement