Title: How to insert binary strings via $wpdb interface?
Last modified: June 23, 2017

---

# How to insert binary strings via $wpdb interface?

 *  [southp](https://wordpress.org/support/users/southp/)
 * (@southp)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/how-to-insert-binary-strings-via-wpdb-interface/)
 * Hi, is there a way to insert a binary string via `$wpdb` interface?
    It looks
   like `strip_invalid_text()` is called by `insert()` and `prepare()`, so my binary
   string is always stripped off. My case is that my table has a `uuid` column which
   is defined as `binary(16)` for compactness. I know changing it to `varchar(36)`
   would work, but I’d love to know if there is a way to work around that before
   making the change.
 * Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/how-to-insert-binary-strings-via-wpdb-interface/#post-9256595)
 * It appears $wpdb doesn’t consider binary as a valid format. It only accepts float,
   integer, string. Your only option is to use PHP mysqli_* functions to interact
   with your table.
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/how-to-insert-binary-strings-via-wpdb-interface/#post-9258363)
 * OK, let’s try again…
 * The WordPress DBAL is designed for newbies who don’t understand SQL basics. That
   is good (I suppose) in some ways, but limits its usefulness for those who are
   more advanced. Thankfully the DBAL has a backdoor that allows more advanced developers
   to completely bypass $wpdb and use mysqli procedural functions.
 * First you should make sure mysqli is being used. I put code similar to the following
   in my activation functions:
 *     ```
       global $wpdb;
   
       if (!extension_loaded('mysqli')) {
       	wp_die('mysqli extension not available. Please upgrade your version of PHP.');
       }
       else if (!$wpdb->__get('use_mysqli')) {
       	wp_die("Please add <strong><code>define('WP_USE_EXT_MYSQL', false);</code></strong> to your wp-config.php file.");
       }
       ```
   
 * At this point you can be assured that the mysqli extension is being used. In 
   the code that initializes the plugin (or in a theme’s functions.php file), add
   the following lines:
 *     ```
       global $dbh;
       $dbh = $wpdb->__get('dbh');
       ```
   
 * You can now use mysqli procedural functions as needed by supplying the $dbh variable
   for the DB handle.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to insert binary strings via $wpdb interface?’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 3 participants
 * Last reply from: [Dion](https://wordpress.org/support/users/diondesigns/)
 * Last activity: [8 years, 11 months ago](https://wordpress.org/support/topic/how-to-insert-binary-strings-via-wpdb-interface/#post-9258363)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
