Subject RE: [firebird-support] dump/restore
Author Nigel Weeks
You could use PHP code like the following:
PHP compiled with --enable-cli (useful for shell scripts, data transfersm
etc)

Ps. This is real rough. Knocked it up when I saw your email.


---- Begin PHP code -----
#!/usr/local/bin/php -e
<?php

// Change the following connection info for your database
$conn = ibase_connect("host:/path/to/database.gdb","sysdba","masterkey");


// Set the following variable to 1 to produce insert statements
$ins = 0;

// Set the field delimiter here
$delim = "'";

// Set the field seperator here
$sep = ",";

// Set the comment character here
$comm = "//";


$tsql = "SELECT distinct(a.rdb\$relation_name) as str_tablename from
rdb\$relation_fields a where a.rdb\$relation_name NOT CONTAINING 'RDB\$'";

$trec = ibase_query($tsql) or die("Bad Table Query");
while($tobj = ibase_fetch_row($trec)){
//We have a table name. Let's pull the data
if($comm){echo "$comm --- ".trim($tobj[0])." ---\n";}
$dsql = "SELECT * FROM ".trim($tobj[0]);
$drec = ibase_query($dsql) or die("Bad Data Query");

// Echo out the field names
echo $comm." (";
$col = 0;
$cols = ibase_num_fields($drec);
for($f=0;$f<$cols;$f++){
$info = ibase_field_info($drec,$f);
echo $info['name']." ";
}
echo ") \n";

// Echo out the data
while($dobj = ibase_fetch_row($drec)){
// Output the row(if $ins is turned on, output insert statements)
if(!$ins){
$col = 0;
while($col < $cols){
echo $delim.$dobj[$col].$delim;
if($col + 1 < $cols){
echo $sep;
} else {
echo "\n";
}
$col++;
}
} else {
echo "INSERT INTO ".trim($tobj[0])." (";
for($col=0;$col < $cols;$col++){
$info = ibase_field_info($drec,$col);
echo $info['name'];
if($col + 1 < $cols){
echo $sep;
}
}
echo ") VALUES (";
for($col=0;$col < $cols;$col++){
echo $delim.$dobj[$col].$delim;
if($col + 1 < $cols){
echo $sep;
}
}
echo ");\n";
}
}
}
?>

--- End PHP code ---