Beispiel #1
0
function pg2mysql_large($infilename, $outfilename)
{
    $fs = filesize($infilename);
    $infp = fopen($infilename, "rt");
    $outfp = fopen($outfilename, "wt");
    //we read until we get a semicolon followed by a newline (;\n);
    $pgsqlchunk = array();
    $chunkcount = 1;
    $linenum = 0;
    $inquotes = false;
    $first = true;
    echo "Filesize: " . formatsize($fs) . "\n";
    while ($instr = fgets($infp)) {
        $linenum++;
        $memusage = round(memory_get_usage(true) / 1024 / 1024);
        $len = strlen($instr);
        $pgsqlchunk[] = $instr;
        $c = substr_count($instr, "'");
        //we have an odd number of ' marks
        if ($c % 2 != 0) {
            if ($inquotes) {
                $inquotes = false;
            } else {
                $inquotes = true;
            }
        }
        if ($linenum % 10000 == 0) {
            $currentpos = ftell($infp);
            $percent = round($currentpos / $fs * 100);
            $position = formatsize($currentpos);
            printf("Reading    progress: %3d%%   position: %7s   line: %9d   sql chunk: %9d  mem usage: %4dM\r", $percent, $position, $linenum, $chunkcount, $memusage);
        }
        $currentpos = ftell($infp);
        $progress = $currentpos / $fs;
        if ($progress == 1.0 || strlen($instr) > 3 && ($instr[$len - 3] == ")" && $instr[$len - 2] == ";" && $instr[$len - 1] == "\n") && $inquotes == false) {
            $chunkcount++;
            if ($linenum % 10000 == 0) {
                $percent = round($progress * 100);
                $position = formatsize($currentpos);
                printf("Processing progress: %3d%%   position: %7s   line: %9d   sql chunk: %9d  mem usage: %4dM\r", $percent, $position, $linenum, $chunkcount, $memusage);
            }
            /*
            			echo "sending chunk:\n";
            			echo "=======================\n";
            			print_r($pgsqlchunk);
            			echo "=======================\n";
            */
            $mysqlchunk = pg2mysql($pgsqlchunk, $first);
            fputs($outfp, $mysqlchunk);
            $first = false;
            $pgsqlchunk = array();
            $mysqlchunk = "";
        }
    }
    echo "\n\n";
    printf("Completed! %9d lines   %9d sql chunks\n\n", $linenum, $chunkcount);
    fclose($infp);
    fclose($outfp);
}
Beispiel #2
0
Boston, MA 02111-1307, USA.
*/
include "pg2mysql.inc.php";
?>
<html>
<head><title>pg2mysql converter (PostgreSQL to MySQL Converter)</title></head>
<body>
<h1>pg2mysql converter (PostgreSQL to MySQL Converter)</h1>

The <b>pg2mysql</b> converter is an online tool to convert/migrate existing PostgreSQL databases into MySQL.  Simply dumping from Postgres and importing to MySQL does not work because of differences in syntax and data types.  To use this converter, just create a postgres SQL dump (<tt>pg_dump -U username -s dbname &gt; dbname.sql</tt>), and copy and paste it into the text area below.  Click the <b>Convert to MySQL</b> button and the page will re-load with your new MySQL code that you can copy out of the textarea into a text editor to save and import into your MySQL database.
<br><br>
<form method=post action="pg2mysql.php">

<?php 
if ($_POST['postgresdata']) {
    $output = pg2mysql(stripslashes($_POST['postgresdata']));
    echo "<h3>Here is your MySQL dump file</h3>";
    echo "<textarea rows=20 cols=80 name=mysqldata>{$output}</textarea>";
} else {
    ?>
 	<h3>Paste PostgreSQL dump file here</h3>
	<textarea rows=20 cols=80 name=postgresdata></textarea>
	<br />
	<input type=submit value="Convert to MySQL">
 <?php 
}
?>


</form>
Beispiel #3
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/

/*
 *   This program reads the output from pg_dump from standard input
 *  and performs syntactical changes to conform with mysql format
 *  onto standard output.
 */

//  Include the appropriate function.

include 'pg2mysql.inc.php';

$in = file_get_contents( 'php://stdin' );

$out = pg2mysql( $in );

//  Output contains no newline characters, so insert them here.
file_put_contents( 'php://stdout', str_replace( ";", ";\n",  $out ) );

exit( 0 );
?>