manalnor Posted April 6, 2010 Share Posted April 6, 2010 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 More sharing options...
DavidAM Posted April 6, 2010 Share Posted April 6, 2010 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. Link to comment https://forums.phpfreaks.com/topic/197695-how-to-dump-database-file/#findComment-1037505 Share on other sites More sharing options...
simshaun Posted April 6, 2010 Share Posted April 6, 2010 Just use MySQL's built-in LOAD DATE INFILE syntax. Link to comment https://forums.phpfreaks.com/topic/197695-how-to-dump-database-file/#findComment-1037508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.