/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Database backup script

I created a script that outputs the following code into a PHP file for EACH table in the database. I am using this as a “ready to run” backup script that i can just include and it will drop all tables, recreate the tables and then reinsert each value.

For some reason i can only get the code to drop the tables, any help is much appreciated. ?

[code=php]mysql_query(“DROP TABLE IF EXISTS usr”);
$sql=”CREATE TABLE page (pge string(1) not_null primary_key, mt string(10000) not_null, mim string(50) not_null, imh string(3) not_null, imw string(3) not_null, tile string(100) not_null, mh string(100) not_null, cue string(1) not_null, su string(1) not_null, PRIMARY KEY (page)) TYPE=MyISAM”;
mysql_query($sql);

mysql_query(“INSERT INTO usr VALUES (‘1’, ‘Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, <span style=”font-weight: bold;”>sed diam voluptua</span>. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, <span style=”font-style: italic;”>consetetur sadipscing elitr</span>, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <br><ul><li><span style=”font-weight: bold;”>ro eos et accusam eAt vet justo duo dolores et ea rebum</span>.</li><li>&nbsp;Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. <br></li><li style=”font-weight: bold;”>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</li><li>&nbsp;At vero eos et accusam et justo duo dolores et ea rebum. <br></li><li style=”font-weight: bold;”>Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li></ul>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. <br>’, ‘StandingHandInPocket.JPG’, ‘350’, ‘233’, ‘Home’, ‘Welcome!’, ‘n’, ‘n’,)”);
mysql_query(“INSERT INTO page VALUES (‘2’, ‘asd<span style=”font-weight: bold;”>fgafgadfg</span><br>’, NULL,NULL,NULL,’page 2′, ‘header2’, NULL,NULL)”);
mysql_query(“INSERT INTO page VALUES (‘5’, ‘<br>’, NULL,NULL,NULL,NULL,NULL,’y’, NULL)”);
mysql_query(“INSERT INTO page VALUES (‘3’, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)”);
mysql_query(“INSERT INTO page VALUES (‘4’, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)”);
[/code]

Thanks,
Jeremy

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@scragarAug 20.2008 — have you tried running:
[code=php]mysql_query($sql) or die(mysql_error()); [/code]?

if you get an error message it's much easier to find the problem.
Copy linkTweet thisAlerts:
@chazzyAug 20.2008 — if you're debugging something, always add debug information

[code=php]
mysql_query("DROP TABLE IF EXISTS usr") or die("Unable to drop usr table: ".mysql_error());
[/code]


Of course you would remove that once you know it's working.

Does the user you're connecting as have the DROP privilege?

why is the rest of the script about the "page" table?
Copy linkTweet thisAlerts:
@JeremyAauthorAug 20.2008 — oh that was a typo on my part, ill try and debug and see what comes up...

Yeah the user im logged in as has full privileges
Copy linkTweet thisAlerts:
@JeremyAauthorAug 20.2008 — It just errors the MySQL syntax, there is no specific error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'string(100) not_null, conm string(100) not_null, lk1 string(100) not_null' at line 1

and as i go down the line and remove the create table code it just errors the next one in line.
Copy linkTweet thisAlerts:
@scragarAug 20.2008 — 1 quick point, that bit isn't in the code you posted, no chance your missing part out that would be helpful is there?
Copy linkTweet thisAlerts:
@JeremyAauthorAug 20.2008 — its basically the same, the script outputs the same for each table so it should be uniform. Also it errors on EVERY table creation when i take out the previous one it will still error. But here is the code the above error came from...

[code=php]mysql_query("DROP TABLE IF EXISTS coating");
$sql="CREATE TABLE coating (bri string(100) not_null, conm string(100) not_null, lk1 string(100) not_null, lk2 string(100) not_null, lk3 string(100) not_null, lk4 string(100) not_null, lk5 string(100) not_null, bt1 string(100) not_null, bt2 string(100) not_null, ba string(10) not_null, btcol string(7) not_null, nlettx string(300) not_null, lgo string(100) not_null, lgow string(3) not_null, lgoh string(3) not_null, sh1 string(15) not_null, sh2 string(15) not_null, id string(1) not_null primary_key, PRIMARY KEY (id)) TYPE=MyISAM";
mysql_query($sql) or die(mysql_error());[/code]
Copy linkTweet thisAlerts:
@scragarAug 20.2008 — you do realise that NOT NULL should be done with a space not an underscore right(which I can't believe I didn't notice before)?

You also realise that string is not a valid field type as well, right? it's either VARCHAR for variable up to the length, or CHAR which is fixed to the length(CHAR is quicker to access since there's less reading, but it's also more space...)
Copy linkTweet thisAlerts:
@JeremyAauthorAug 20.2008 — oh wow, im surprised i didnt catch that as well. along with the sting() thats an error on page which finds the field type.

Thanks for your help, sorry for not looking over my more carefully :/
×

Success!

Help @JeremyA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...