Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #Connection variables for MYSQL:
- $mysql_host = 'SERVER';
- $mysql_user = 'haldur';
- $mysql_password = 'PAROOL';
- $mysql_database = 'test';
- $mysql_link = new PDO(
- "mysqli:host=$mysql_host;dbname=$mysql_database;charset=utf8",
- $mysql_user,
- $mysql_password
- );
- #Connection variables for MSSSQL:
- $mssql_host = '213.168.13.18:1433';
- $mssql_user = 'VAATAJA';
- $mssql_password = 'PAROOL';
- $mssql_database = 'BAAS';
- $mssql_link = new PDO(
- "dblib:host=$mssql_host;dbname=$mssql_database",
- $mssql_user,
- $mssql_password
- );
- $tables = array('TABEL'); # tabeli nimed siia
- #Select the databases:
- #SET CHARACTER SET to utf8:
- $mysql_link->prepare("SET NAMES 'utf8'")->execute();
- $mysql_link->prepare("SET CHARACTER SET 'utf8'")->execute();
- #Delete all records on MYSQL tabel:
- $deleteQuery = "DELETE FROM TABEL";
- #Migrate the data:
- foreach($tables as $table){
- $deleteQuery = "DELETE FROM $table";
- try{
- $mysql_link->prepare($deleteQuery)->execute();
- }
- catch (PDOException $e){
- echo $e->getMessage();
- }
- $m_res = $mssql_link->prepare('select * from ?')->execute($table);
- $j = 0;
- while($rec = $m_res->fetch(PDO::FETCH_NUM)){
- echo $table, ' >> ', $j++, "\n";
- $cols = count($rec);
- for($i = 0; $i < $cols; $i++){
- if(is_string($rec[$i])){
- $rec[$i] = $mysql_link->quote($rec[$i]);
- }
- if(is_null($rec[$i])) $rec[$i] = 'NULL';
- }
- $query .= "(" . implode(",", $rec) . "),";
- }
- $sql = "INSERT INTO ? VALUES ". $query;
- try{
- $mysql_link->prepare($sql)->execute($table);
- }
- catch (PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement