Tuesday, September 21, 2010

Howto and tips :converting from #mysql to #firebirdsql

here are some basic types to be converted from mysql to firebirdsql when you run the create table scripts


  • int(10)->int
  • smallint(5)->int
  • datetime->timestamp
  • replace the ` with double quote " or with nothing


dump the database with full inserts and then run it with flamerobin
mysqldump  -u root --password=mysql_password -t -c dbname tablename > /tmp/foo.sql

another option is to put dump table in csv format and import it using a php script
that fetches each row and inserts it into firebird table
here is one example for a table with 3 columns

<?php
// Connection
$db='10.0.0.x:/var/lib/firebird/2.5/data/mysql2firebird.fdb';
$dbuser = 'SYSDBA';
$dbpass = '*******';
$res = ibase_connect($db,$dbuser,$dbpass) or die("<br>" . ibase_errmsg());
$row = 1;
$handle = fopen("mysqltable_dump.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
// echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
if ($data[$c]=="") {$data[$c]="null";}
// echo $data[$c] . "<br />\n";
}
$query="insert into firebird_table_name(firestcolumn_id,second_column,third_column) values (".$data[0].",".$data[1].','.$data[2].");";
echo "$query\n";
$result=ibase_query($res,$query);
ibase_commit($res);
if (!$result) {
echo "Error. Can't insert the record with the query: $query!";
exit;
}
}
fclose($handle);
?>


or search for a tool that will do that for you

No comments: