How to import firebird data into mysql?

3

How to import data from Firebird to Mysql using PHP ?

    
asked by anonymous 18.06.2014 / 13:44

1 answer

3
  

The answer below was originally posted as a question by the author of the question. I now post as Community Wiki to register.

Some time ago I had to import the data from a firebird table to another table in mysql, at the time I did not find anything ready that met the needs so I researched and put the code below.

<?php
set_time_limit(0);//zera o limite de tempo

//conexão com mysql
$mysql=mysql_connect('localhost','root','root');

//conexão com firebird
$ibase=ibase_connect('C:\RAAS.GDB', 'SYSDBA', 'masterkey') or die ('Erro ao conectar');
$i=0;


$busca=ibase_query("SELECT CD_COD, CD_DESCR FROM S_CID",$ibase);
$count=ibase_fetch_object($busca);
$total=count($busca);

while($row=ibase_fetch_object($busca)){

    //dentro da query o nome raas.cid10 são banco de dados e tabela
    $sql =mysql_query("insert into raas.cid10 (codigo, descricao) values ('".$row->CD_COD."', '".substr($row->CD_DESCR,5,100)."') ",$mysql);
    $i++;

    $largura=(($i*100)/$total);//calcula andamento da operação em percentual
    $perc=(int)($largura);
    echo "<div style='width:300px; height:20px; background:#fff; border:1px solid #f00; position:absolute; top:55px; left:10px'>
        <div style='width:$largura%; height:20px; background:#f00; position:absolute; top:0; left:0'></div>
    </div>

    <div style='width:100px; height:20px; background:#fff; position:absolute; top:95px; left:155px'>$perc</div>
    ";

}
if($sql){
echo $i."registros importados";
}

?>
    
19.06.2014 / 02:09