Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.