开发者

php import larg table to phpmyadmin database

I dropped one of the tables from the database accidentally. fortunately, I have back-up. (I have used the "Auto backup for mysql")

The back-up of the table is stored as .txt file (56 Megabytes) on my PC.

I tried to import it by PhpMyAdmin and the import failed because the file is too large to import.

then I uplo开发者_高级运维aded the file to /home/tablebk directory. I have some experiences in php. I know that I would import it with this code, but i don't know the sql statment for this import.

what is have to put as $line variable?

please help me :( :(

<?php

    $dbhost = 'localhost';          
$dbuser = 'mysite';         
$dbpw = 'password';         
$dbname = 'databasename';

$file = @fopen('country.txt', 'r');

if ($file)
{
    while (!feof($file))
    {
        $line = trim(fgets($file));
        $flag = mysql_query($line);

        if (isset($flag))
        {
            echo 'Insert Successfully<br />';
        }

        else
        {
            echo mysql_error() . '<br/>';
        }

        flush();
    }

    fclose($file);
}

echo '<br />End of File';

?>


Why not use MySQL's batch commands:

shell> mysql db_name < text_file


Try BigDump, which solves the problem elegantly and reliably. It basically does what you want, but with more safety mechanisms and several ways to restart in the middle of the file. Also, it has beautiful progress indicators, and... oh, it's already written, so you don't need to write your own script. No need to reinvent the wheel. (I'm not affiliated with BigDump or its developer(s) in any way.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜