How to Export and Import MySQL Database using PHP

preview_player
Показать описание
The basic idea is to dump database table structure and data into a SQL file for backing up. While restoring, the SQL queries dumped into the file are executed one after another.
Рекомендации по теме
Комментарии
Автор

You really saved me, thx you very much

_jbars_
Автор

Thank you so much for this video. I have a question: How can i export all database in MySQL?

ThanhNguyen-firw
Автор

This only for single page how to take backup for larger table around 4000 and page around 95 can you help me on this because in single time there is only option to backup single page how can we get backup for hole page in single time.

ZASCOGPS
Автор

This works but when importing, it will have problems on tables with foreign keys

cecironalejoiii
Автор

thank you bro it's very use full...

doyoulikeit..
Автор

sir can you explain how to do with postgresql/

-PRIYANKAGADEWAR
Автор

hi how do we add NULL as NULL value and BLANK as blank in insert query, here all NULL are converted to blank in insert query

relyontestmail
Автор

This code is not working, I do not know why.

abdullahfazli
Автор

files successully back but didnot show thee sucessfully message

phootoflirtnone
Автор

Can someone tell me how to change the path?? and can i make several copies? with the current date

andreaarias
Автор

/*This is the correct backup code but it doesn't include the database itself only the data inside the database*/

<?php
$connection = mysqli_connect("localhost", "root", "", "test"); //admin is the database to be backed up



// get all tables of the database
$tables = array();
$result = mysqli_query($connection, "SHOW TABLES");
while($row = mysqli_fetch_row($result)){

$tables[] = $row[0];
}

$return = '';
foreach($tables as $table){

$result = mysqli_query($connection, "SELECT * FROM ".$table);
$num_fields = mysqli_num_fields($result);

$return .= 'DROP TABLE '.$table.';';
$row2 = mysqli_fetch_row(mysqli_query($connection, 'SHOW CREATE TABLE '.$table));
$return .= "n\n\'".$row2[1]."';\n\n";


while($row = mysqli_fetch_row($result)){
$return .= 'INSERT INTO '.$table.' VALUES(';

$row[$j] = addslashes($row[$j]);
if(isset($row[$j])){ $return .= '"'.$row[$j].'"';} else { $return .= '""';}
if($j<$num_fields-1){ $return .= ', ';}
}
$return .= ");\n";
}
}
$return .= "\n\n\n";

}
//save file
$handle = fopen('backup.sql', 'w+');
fwrite($handle, $return);
fclose($handle);
echo"Successfully backed up";

?>

michael
Автор

i have see 150 time but need project file

freelancerwebdeveloper
Автор

I've a file of 25Mb and not work..!

PS: for next time, paste the codes..!

DonaWinit
Автор

this is not backup database. This is only create table you lie all of friends

khuelovehawj
Автор

good, but if you share this source code then become well.

brightscript