• Hi,

    I am writing a plugin and am working with the wp_posts and wp_meta table. As I am working my way through the testing, I have realized, that I would like to restore the above 2 tables before each test run programatically as part of my plugin, so I may better guage the results. What is the best approach to doing this?

    Thanks in advance,

    KC

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kc11

    (@kc11)

    Hello,

    I’ve come up with the following function:

    function resetdatabase($tablename,$backup_tablename) {
        global $wpdb;
        //$tablename='wp_posts';
    
    	print 'Resetting '.$tablename.' from '.$backup_tablename;
    
    //  drop table if exists
    $sql = "DROP TABLE IF_EXISTS '$tablename'";
    print $sql;
    $wpdb->query($sql);
    
    //die(var_dump($e));
    
     $e = $wpdb->query("CREATE TABLE $tablename LIKE $backup_tablename");
     var_dump($e);
     $e = $wpdb->query("INSERT INTO $tablename SELECT * FROM $backup_tablename");
     var_dump($e);

    I have created backup tables in the wordpress database called posts1 and postmeta1, using phpmyadmin. However the tables wp_posts and wp_postmeta are not being dropped, even though I have granted all privileges to the wordpress user in phpmyadmin. The output is as follows:

    Resetting wp_posts from posts1DROP TABLE IF_EXISTS ‘wp_posts’

    boolean false

    boolean false

    does anyone know why I can’t drop the tables?

    Thanks,

    KC

    Thread Starter kc11

    (@kc11)

    in phpmyadmin the privileges table looks like:


    Users having access to “wordpress”

    User Host Type Privileges Grant Action
    admin localhost global ALL PRIVILEGES Yes Edit Privileges
    root 127.0.0.1 global ALL PRIVILEGES Yes Edit Privileges
    root localhost global ALL PRIVILEGES Yes Edit Privileges
    wordpress localhost global ALL PRIVILEGES Yes Edit Privileges
    database-specific ALL PRIVILEGES No Edit Privileges

    I am calling my project : ‘ wordpress2 ‘

    Interestingly, This function does work to create a new table and insert new data (later on in the function) , but will not drop the table.

    Thanks in advance,

    KC

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Backing up wp tables in test environment’ is closed to new replies.