Jump to content

How to dump database file


manalnor

Recommended Posts

Hello friends,

 

if i've php file config.php that connect to database

then if i have database file called db.sql

 

how to create php file that

1- connects to db using config.php

require "config..php";

2- Dumpe the file db.sql into the database

 

thanks in advance

i know there is way to rewrite it such as

 

$q1 = "CREATE TABLE table_name_here (
**** filded here *****
)";
mysql_query($q1) or die(mysql_error()." at row ".__LINE__);

 

but i was always wonder is there any way to auto-dumpe the file with no needs to rewrite it as php file

 

thanks

 

Link to comment
https://forums.phpfreaks.com/topic/197695-how-to-dump-database-file/
Share on other sites

look at the file_get_contents() function (http://us2.php.net/manual/en/function.file-get-contents.php).  You can use it to load the db.sql file into a string and send the string to the database.

 

Note: if you are using mysql, the string you send to the database can contain only a single command.  So if you have multiple create table statements (or anything else) in the file, you will have to split it up.  I usually explode() on the semi-colon, and then walk the resulting array passing each entry to the database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.