• Resolved netstepinc

    (@netstepinc)


    In this other thread:
    https://www.ads-software.com/support/topic/export-import-tabs-content-from-phpmyadmin/

    Your support response yikesitskevin (@yikesitskevin) 4 months, 2 weeks ago
    “Did you perhaps run any search and replace functions on the database before/after you imported the tabs? If the content of the tab was changed at all, they wouldn’t be imported properly.”

    I’m in desperate need of a search/replace within the tab data.
    I’ve attempted very minor edits such as deleting 4 characters.
    The original imports fine, but the slight edit does not.

    Is there a trick to doing this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter netstepinc

    (@netstepinc)

    I built an external script that enabled me to unserialize > edit > serialize and update the meta_values.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    That is the perfect way to go about editing tabs from the code @netstepinc.

    Would you mind sharing your script?

    Thread Starter netstepinc

    (@netstepinc)

    This is not fancy, but it worked for me.
    edit_yikes_tabs.php

    
    <?php
    /*INSTRUCTIONS
    WARNING: This is built for a specific purpose and limited use. Do not leave this in your website in the current form.
    NOTE: URL parameter &go=0 is for testing. &go=1 will execute the update so don't change that until you're ready.
    
    1. Copy db settings from wp-config file and paste below
    2. Define the TABLE_POSTMETA value below.
    3. Upload to your website web directory
    4. Test it at https://EXAMPLE.COM/edit_yikes_tabs.php?search=FIND&replace=REPLACE&go=0
    5. DELETE the file from your website when done. This is quick primitive unsecure code.
    */
    
    //DB CONNECT
    define('DB_NAME','');
    define('DB_USER','');
    define('DB_PASSWORD','');
    define('DB_HOST', 'localhost');
    define('TABLE_POSTMETA','wp_postmeta');
    
    $search = $_GET['search'];
    $replace = $_GET['replace'];
    $execute = $_GET['go'];
    
    echo '<div>SEARCH: '.$search.'</div>';
    echo '<div>REPLACE: '.$replace.'</div>';
    
    // Create connection
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if ($mysqli->connect_error) {
    	die("Connection failed: " . $mysqli->connect_error);
    } 
    mysqli_set_charset($mysqli,"utf8");
    
    // Perform an SQL query
    $sql = "SELECT <code>meta_id</code>,<code>meta_value</code> from ".TABLE_POSTMETA." where <code>meta_key</code> = 'yikes_woo_products_tabs'";
    
    // to get the error information
    if (!$result = $mysqli->query($sql)) {
        echo "Error: Our query failed to execute and here is why: \n";
        echo "Query: " . $sql . "\n";
        echo "Errno: " . $mysqli->errno . "\n";
        echo "Error: " . $mysqli->error . "\n";
        exit;
    }
    if ($result->num_rows === 0) {
        echo "No results";
        exit;
    }
    
    while ($data = $result->fetch_assoc()) {
    	$value = unserialize($data['meta_value']); 
    
    	echo '<div style="margin:10px; padding:10px; border:1px solid #00CC00; background:#FFFFCC">';
    	echo 	'ORIGINAL SERIALIZED TAB DATA: <b>postmeta id: ' . $data['meta_id'] . '</b><br>' . $data['meta_value'];
    	echo 	'<hr><b>BEFORE</b><br>'; print_r($value);
    
    	for($i=0; $i < count($value); $i++){
    		$content = $value[$i]['content'];
    		if(strstr($content,$search) == true){
    			$value[$i]['content'] = str_replace($search,$replace,$content);
    		}
    	}
    	$new_value = serialize($value);
    
    	echo 	'<hr><b>AFTER</b><br>'; print_r($value);
    	echo 	'<hr><b>SERIALIZED</b><br>'.$new_value;
    	
    	$update = "update wpso_postmeta set <code>meta_value</code> = '".$new_value."' where <code>meta_id</code>= '".$data['meta_id']."'";
    	if($execute == 1){
    		echo '<hr color="green" size="2"><b>UPDATE QUERY</b><br>'.$update;
    		$mysqli->query($update);
    	}
    	echo '</div>';
    }
    ?>
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘phpMyAdmin: Export – Edit – Import’ is closed to new replies.