View Full Version : Need PHP code for exporting *.sql
AZone
12-20-2002, 08:32 PM
I have *sql file (back-up of my forum).
Now I need install (export, extract...) it, but my server doesn't have any Web-manager (like phpMyAdmin, nothing at all) and doesn't allow CGI sripts.
Only one way - PHP
I have sample, but it doesn't work:
<?php
$sqlEx = "sql"; //
$schema = "vbulletin"; //
$sql = explode(";", implode("", file("./".$schema.".".$sqlEx)));
for ($i = 0; $i < count($sql); $i++) mysql_query($sql[$i]) or
die(mysql_error());
?>
I have message - "No Database Selected"
Help me, please!
NTLDR
12-20-2002, 09:24 PM
Why not just use the built-in backup script in the ACP?
AZone
12-20-2002, 09:30 PM
I saw only import function there, which makes *.sql file. But now I already made *.sql and I need export it to another forum. Is it possible in ACP?
NTLDR
12-20-2002, 09:33 PM
Yes you can create a .sql file to import into another DB: ACP -> Back-up Database and then either the first option, where you download, or the second option where you can save it to the server :)
AZone
12-20-2002, 09:39 PM
I said: I already create this file, I have this file.
I need opposite function! Install *sql file, which already exist!
tHE DSS
12-20-2002, 09:40 PM
I see what you need.
You need this :
http://www.scibit.com/Products/Software/Utils/Mascon.htm
:cool:
... try out the Freeware version... see if you like it... if you do, you'll have to pay for the full version to be able to put your backup databases back.
At only $49, it's a bloody bargain!!!
With that, you wouldn't even need a backup. You could just make a copy from one server, and dump it directly to the other. Sweet as a nut!!
I was pointed to that utility because our forums database got too large for the vB Admin CP to handle, and we don't have Telnet access to our webserver.
With this application, I can manipulate our database fully.... I can even get rid of the potential security problem of using phpMyAdmin from the web server. :devious:
One thing though.... you will need to go through the vB database structure, and change any fields that are set to NOT NULL, to NULL... as some fields in some records will be blank, even though they shouldn't have NULL values.
When importing a database, you'll notice that it will halt part the way through, due to that error cropping up.
You can always go back and set the NULL fields back to NOT NULL when you've properly imported.
That shoud only affect fields that accept alphanumeric data though. Not INTEGER, and such.
Another thing.... DO NOT EVER set the program to CONTINUE ON ERRORS... because it will continue, but you won't have a complete database.
Anyway... that's what you are looking for. I am 100% you will be happy with it. I am.
tHE DSS
12-20-2002, 09:45 PM
p.s : you can schedule backups with that application too.
Being able to fully backup, restore.... copy from server to server directly... shedule those operations... etc. etc. etc. etc. etc.
It's a MUST HAVE UTILITY FOR A MySQL Admin. ;)
AZone
12-20-2002, 09:49 PM
No, I don't have $50 for only one operation - I need to do it only once.
I cannot replace forum from localhost to the internet! Help!
NTLDR
12-20-2002, 09:57 PM
Originally posted by AZone
I said: I already create this file, I have this file.
I need opposite function! Install *sql file, which already exist!
Sorry, I miss-read you post, to me Import doesn't suggest a database backup.
Visit sourceforge.net and install phpMyAdmin on your server yourself as your host doesn't provide it.
AZone
12-20-2002, 09:59 PM
NP
Really? I can install phpMyAdmin myself?
tHE DSS
12-20-2002, 10:02 PM
Yes, you can install it yourself.
But, I do recommend that Mascon over it any day of the week. For 100 reasons... apart from it not being Freeware. But $49 for somthing you'll be well glad you had in your tool box (for a long long time), is a pretty nice investment.
You will need to be taking backups of your database regular anyway. You may aswell have a smooth procedure for doing it.
Anyway, your original problem was that you didn't seem to be stating any connections to a database server, and not selecting a database.
Try somthing like this :
$destinationLink = mysql_connect("destinationServerName", "username", "password") or die("Could Not Connect To DESTINATION database");
$connectDestination = mysql_select_db("destinationDatabaseName", $destinationLink) or die ("Could Not Select DESTINATION database");
$sqlEx = "sql"; //
$schema = "vbulletin"; //
$sql = explode(";", implode("", file("./".$schema.".".$sqlEx)));
for ($i = 0; $i < count($sql); $i++) mysql_query($sql[$i], $destinationLink) or die(mysql_error());
... Good luck. :bunny:
AZone
12-20-2002, 11:26 PM
Thanks a lot! I did it!
Bubba
12-23-2002, 04:02 AM
Some advice on using phpMyAdmin, if you can get the admin to only allow you and the "web user" access to it via file permissions. This prevents another user from being able to read the db password from the config files.
Also, when you're not using it, chmod the whole directory tree to 700. The prevents some random web user from accessing it when you're not using it.
And of course, don't use phpMyAdmin for the folder name......
If anyone knows any other good techniques to help safeguard this app, please let me know :)
Sebastian
12-23-2002, 05:22 AM
I have that Mascon application, how do you schedule backup automatically? i don't see that option, i have the full version.
DrkFusion
12-23-2002, 01:17 PM
Also if you have huge databases in phpmyadmin, when you try to import the huge sql file, you will get timeouts errors, you will have to use little snippets that phpmyadmin can digest it.
tHE DSS
12-23-2002, 05:36 PM
Originally posted by Sebastian
I have that Mascon application, how do you schedule backup automatically? i don't see that option, i have the full version.
You should be able to either use the application from the command line, or you will have a command line utility supplied with the package.
You can then create a little batch file, or somthing similar.
I got to admit though, the documentation with Mascon isn't all that hot. :ermm:
The developers would supply good support for it though.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.