Results 1 to 9 of 9

Thread: [RESOLVED] Database backup script

  1. #1
    Join Date
    Jul 2008
    California, US

    resolved [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.

    PHP Code:
    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("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)");

  2. #2
    Join Date
    Jun 2003
    have you tried running:
    PHP Code:
    mysql_query($sql) or die(mysql_error()); 

    if you get an error message it's much easier to find the problem.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    Aug 2005
    The Garden State
    if you're debugging something, always add debug information

    PHP Code:
    mysql_query("DROP TABLE IF EXISTS usr") or die("Unable to drop usr table: ".mysql_error()); 
    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?
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  4. #4
    Join Date
    Jul 2008
    California, US
    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

  5. #5
    Join Date
    Jul 2008
    California, US
    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.

  6. #6
    Join Date
    Jun 2003
    1 quick point, that bit isn't in the code you posted, no chance your missing part out that would be helpful is there?
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  7. #7
    Join Date
    Jul 2008
    California, US
    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...

    PHP Code:
    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()); 

  8. #8
    Join Date
    Jun 2003
    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...)
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  9. #9
    Join Date
    Jul 2008
    California, US
    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 :/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.16832 seconds
  • Memory Usage 2,936KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (9)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates