SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to recover from accidential query

    Hey,

    I've been wondering if there is a tool(or command) through sql where it can revert back to an older stage (without having to back up the entire database) in case of an accidental update/delete/drop/etc..

    I've been doing some research on this but only find tools for MS SQL. Any info is greatly appreciated, thanks.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If you use INNODB tables in mySQL then you can set up transactions. That allows multiple queries to be run with a decision made at the end to keep them all by doing a commit or to discard them all and restore back to the starting point at any stage prior to the commit.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm..

    I'm not sure if that would work since I manipulate the database through PHP?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by 9three View Post
    Hm..

    I'm not sure if that would work since I manipulate the database through PHP?
    No you manipulate the database through mySQL queries. The language you use to run those queries is irrelevant.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if you do

    Code PHP:
    $strQuery = 'UPDATE customers
                         SET name = $name';

    But instead you meant to do

    Code PHP:
    $strQuery = 'UPDATE customers
                         SET name = $name
                         WHERE id = 7';

    Is it possible to recover from that?

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by 9three View Post
    Is it possible to recover from that?
    You mean recovering from errors in the original code. The simplest way is to test thoroughly first before you implement the code so that it doesn't contain stupid errors like that. If an error like that ends up in the live code then the only way to recover after the event is to restore back to a previous backup of the database.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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