Sunday, October 03, 2010

Howto and tips :converting from #mysql to #firebirdsql Part 2

In the first part i have showed you a method using csv files but there is
a smarter way to migrate from mysql or mssql , get the column info :name,type,pks http://www.php.net/manual/en/function.mysql-fetch-field.php
after that for each table we can create the table in firebird
1. get tables,get tables columns , types relations from mysql , or mssql (for that i will do an article later)
2. for each table, column create new tables with columns in firebird
3. for each row in each table select from mysql,mssql and insert in corresponding table in firebird
in a similar way we did in previous example but there i have inserted from csv
http://gist.github.com/589903
for mssql i will write another script for info , there is one sp that gives you just that
and we can use one query to get it

Here is the first sub step get all the columns info for one table

<?php
/*
a smarter way to migrate , get the column info :name,type,pks http://www.php.net/manual/en/function.mysql-fetch-field.php
after that for each table we can create the table in firebird
1. get tables,get tables columns , types relations from mysql , or mssql (for that i will do an article later)
2. for each table, column create new tables in firebird
3. for each row in each table select from mysql,mssql and insert in corresponding table in firebird
in a similar way we did in previous example but there i have inserted from csv
http://gist.github.com/589903
for mssql i will write another script for info , there is one sp that gives you just that
and we can use one query to get it
*/
$conn = mysql_connect('host', 'user', '*******');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('migrate_db_mysql2firebird');
$result = mysql_query('select * from migration_source_table');
if (!$result) {
die('Query failed: ' . mysql_error());
}
/* get column metadata */
$i = 0;
while ($i < mysql_num_fields($result)) {
echo "Information for column $i:<br />\n";
$meta = mysql_fetch_field($result, $i);
if (!$meta) {
echo "No information available<br />\n";
}
echo "<pre>
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
name: $meta->name
not_null: $meta->not_null
numeric: $meta->numeric
primary_key: $meta->primary_key
table: $meta->table
type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
</pre>";
$i++;
}
mysql_free_result($result);
?>

No comments: