Skip to content

Instantly share code, notes, and snippets.

@ondrejmirtes
Created October 3, 2010 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ondrejmirtes/608677 to your computer and use it in GitHub Desktop.
Save ondrejmirtes/608677 to your computer and use it in GitHub Desktop.
<?php
require_once(__DIR__ . '/dibi.min.php');
dibi::connect(array(
'driver' => 'postgre',
'host' => 'localhost',
'dbname' => 'database',
'user' => 'username',
'password' => '***',
'charset' => 'utf8',
));
$tables = array('table1', 'table2');
///////////////////////////////////////////////////////
header('Content-Type: text/html; charset=utf-8');
function implodeEscape($glue, array $array) {
foreach($array as $key => $value) {
if (!is_numeric($value)) {
$array[$key] = dibi::getConnection()->getDriver()->escape($value, dibi::TEXT);
}
}
return implode(', ', $array);
}
foreach($tables as $table) {
$result = dibi::fetchAll('SELECT * FROM %n', $table);
foreach($result as $row) {
$row = $row->toArray();
echo 'INSERT INTO ' . $table . ' (' . implode(', ', array_keys($row)) . ') VALUES (' .
implodeEscape(', ' , $row) . ');';
echo "<br />\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment