• Hi, I’m trying to save some space on the database when I store large size strings.
    The idea is to use a compressor like the PHP gzcompress( $data ) when I store the data using:

    
    global $wpdb;
    $sql = " UPDATE table SET field = %s WHERE user_id = {$this->user_id} ";
    $sts = $wpdb->query( $wpdb->prepare( $sql, $data ) );
    

    then when I need to get the data:

    
    $sql = " SELECT field FROM table WHERE user_id = {$this->user_id} ";
    $dt = $wpdb->get_results( $sql, OBJECT );
    

    and get the uncompressed data using gzuncompress($st[0]->field).
    Does anyone have any idea on how to do it without killing the database myself by injecting uncontrolled binary data?

    or eventually on how to use something like:

    
    global $wpdb;
    $sql = " UPDATE table SET field = COMPRESS( %s ) WHERE user_id = {$this->user_id} ";
    $sts = $wpdb->query( $wpdb->prepare( $sql, $data ) );
    

    to compress and:

    
    $sql = " SELECT UNCOMPRESS( field ) FROM table WHERE user_id = {$this->user_id} ";
    $dt = $wpdb->get_results( $sql, OBJECT );
    

    to uncompress?

    • This topic was modified 3 years, 11 months ago by antonop4u.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Dion

    (@diondesigns)

    If you store compressed table data, the data will not be available for querying. I suspect that would break WordPress, and at a minimum, searches of any type would no longer be possible.

    In addition, there is nothing you can do to compress data in the WordPress-defined tables unless you write a plugin that monitors every query and adjusts them on-the-fly. You would also need to turn off DB table updates when WordPress updates; otherwise, WordPress would revert the data type changes to table columns that must be made to support binary data.

    If you want to store compressed data in a table you have created, then it’s easy. Instead of using VARCHAR/TEXT/LONGTEXT data types, use VARBINARY/BLOB/LONGBLOB. But note the above issue with querying compressed data.

    Thread Starter antonop4u

    (@antonop4u)

    Ok, Thanks for the warning.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘COMPRESS and UNCOMPRESS data for the database’ is closed to new replies.