473,652 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import .sql file via PHP

Does anyone know how to import a .sql dump file into a mysql database using
php. I know how to do it using commandline, mysql < test.sql, but I am
writing an install script, and was wondering if it is possible to do it this
way. If not, do you know of any parser that will do all the importing/table
creation the .sql file defines? Any response is much appreciated.

Thanks,
Jamie
Jul 17 '05 #1
8 25429

"Jamie Meyers" <gt*****@mail.g atech.edu> wrote in message
news:d7******** **@news-int2.gatech.edu ...
Does anyone know how to import a .sql dump file into a mysql database
using php. I know how to do it using commandline, mysql < test.sql, but I
am writing an install script, and was wondering if it is possible to do it
this way. If not, do you know of any parser that will do all the
importing/table creation the .sql file defines? Any response is much
appreciated.

Thanks,
Jamie


I saw these instructions in the install text for PBS, an AMP program.

"Now we put data in our fresh database. In directory pbs/dump is a dump with
example data. Use mysql dbname < pbssample_engli sh.dmp.
(dbname is $db_name in environment.php 3)"

I think the dump delivered database structure for a help desk program,
PBS. I don't know much about this so you got "any response".

Another example:
a..
1.. go to the directory where the command mysql is recognized and type the
commands displayed in bold below:
a.. prompt$ mysql
b.. mysql> create database allonto;
c.. mysql> quit
d.. prompt$ mysql allonto < allonto.dmp

1.. Run the following command to dump your Mysql database:
2.. mysqldump -f -t -n >bacula-backup.dmp>
a..
Jul 17 '05 #2
Nevermind, I decided to parse the .sql file and create the query there. I
do not think there is any way to import the .sql file via php. Thanks
anyways. And if anyone would like this script after I fix it up a little
more, let me know.

Jamie

"Stephen Harris" <cy************ *******@yahoo.c om> wrote in message
news:Iu******** ******@newssvr2 1.news.prodigy. com...

I saw these instructions in the install text for PBS, an AMP program.

"Now we put data in our fresh database. In directory pbs/dump is a dump
with example data. Use mysql dbname < pbssample_engli sh.dmp.
(dbname is $db_name in environment.php 3)"

I think the dump delivered database structure for a help desk program,
PBS. I don't know much about this so you got "any response".

Another example:
a..
1.. go to the directory where the command mysql is recognized and type
the commands displayed in bold below:
a.. prompt$ mysql
b.. mysql> create database allonto;
c.. mysql> quit
d.. prompt$ mysql allonto < allonto.dmp

1.. Run the following command to dump your Mysql database:
2.. mysqldump -f -t -n >bacula-backup.dmp>
a..

Jul 17 '05 #3
Jamie Meyers wrote:

Does anyone know how to import a .sql dump file into a mysql database using
php. I know how to do it using commandline, mysql < test.sql, but I am
writing an install script, and was wondering if it is possible to do it this
way. If not, do you know of any parser that will do all the importing/table


If you know how to do it with a commandline what's wrong with
exec("mysql < test.sql"); ?
Jul 17 '05 #4
On 2005-05-30, Jamie Meyers <gt*****@mail.g atech.edu> wrote:
Nevermind, I decided to parse the .sql file and create the query there. I
do not think there is any way to import the .sql file via php. Thanks
anyways. And if anyone would like this script after I fix it up a little
more, let me know.


Assuming each instruction is on a line.. (untested)

$db = mysql_connect(. ...);
mysql_select_db (....);

$fp = fopen('somefile .sql', 'r');
while($fp != feof())
{
$line = fread($fp, 2048);
$line = mysql_real_esca pe_string($db, $line);
mysql_query($li ne);
}
fclose($fp);
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be >
Jul 17 '05 #5
Anonymous пишет:
Jamie Meyers wrote:
Does anyone know how to import a .sql dump file into a mysql database using
php. I know how to do it using commandline, mysql < test.sql, but I am
writing an install script, and was wondering if it is possible to do it this
way. If not, do you know of any parser that will do all the importing/table

If you know how to do it with a commandline what's wrong with
exec("mysql < test.sql"); ?

can be denied on public hostings!
Jul 17 '05 #6
Tim Van Wassenhove ÐÉÛÅÔ:
On 2005-05-30, Jamie Meyers <gt*****@mail.g atech.edu> wrote:
Nevermind, I decided to parse the .sql file and create the query there. I
do not think there is any way to import the .sql file via php. Thanks
anyways. And if anyone would like this script after I fix it up a little
more, let me know.

Assuming each instruction is on a line.. (untested)

$db = mysql_connect(. ...);
mysql_select_db (....);

$fp = fopen('somefile .sql', 'r');
while($fp != feof())
{
$line = fread($fp, 2048);
$line = mysql_real_esca pe_string($db, $line);
mysql_query($li ne);
}
fclose($fp);

I guess it will NOT working, because of line can be much more than 2048
bytes, or it can be BLOB or another..
Or, can be comment multi line. your script will failed.
Jul 17 '05 #7
On 2005-05-30, Ivan Omelchenko 608308824 <ne**@omelchenk o.com> wrote:
Tim Van Wassenhove ÐÉÛÅÔ:
Assuming each instruction is on a line.. (untested)

I guess it will NOT working, because of line can be much more than 2048
bytes, or it can be BLOB or another..
That is up to the OP to find out what his needs are..

Or, can be comment multi line. your script will failed.


That wouldn't meet the "each instruction is on a line" requirement..
Meaby a file_get_conten ts and mysqli_multiy_q uery are better suited for
the task..
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #8
If you have ever seen a mysql dump, it is just a dump of all the tables, and
all the data in the tables, unless specified otherwise. Everything is
broken up into multiple lines. A simple while statement worked for me, but
i just need to finish the error checking of the script. I will post it when
I am done.

Jamie
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6906
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
6
8903
by: bry | last post by:
Hi, I'm trying to do a dynamic import of a file that has no problems with it, that is to say I can import it normally, my sys.path is set to the right folder etc. but my dynamic import code is not working, this is the problem code: try: import f except: print "not importable"
1
2376
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the rest of my application (read this as for any imported module) if I import in in a 'higher-level' module. For example: A.py ====
5
2468
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for kk in k:
1
2191
by: Learning Python | last post by:
An example in the book I didn't understood well two modules files recursively import/from each other in recur1.py,we have: x=1 import recur2 y=1
2
3072
by: David Berry | last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the user has the ability to upload a file (.txt or .csv). The data in the file may be comma delaminated, tab delaminated, fixed width etc (we don't know). What I'd like to create is something like MS Access uses to import an Excel file into the...
16
3101
by: didier.doussaud | last post by:
I have a stange side effect in my project : in my project I need to write "gobal" to use global symbol : .... import math .... def f() : global math # necessary ?????? else next line generate an error message ?????
2
2567
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made the mistake of running a test program from the same directory where I built and installed my package. Python uses the package from the current directory, which misses the pyd files, instead of the site-packages package which has them installed. ...
6
2357
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the problem also with other imports (e.g. urllib2 etc.). And again very often in all these cases where I get weired Python exceptions, the problem is around re-functions - usually during re.compile calls during import (see some of the exceptions below). But...
3
12084
by: yinglcs | last post by:
Hi, i have 2 python files in *different directory* , how can I import python functions from 1 python file to another? i get this error: import task ImportError: No module named task/ Thank you.
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.