Support » Plugins » Hacks » Possible to use MySQL functions in insert, update, replace?

  • I cannot figure out how to use MySQL functions, such as NOW(), in $wpdb->insert(), ->update() or ->replace()? The same is true of a MySQL bit string (e.g., v=b’0101010′). None of the available data types (%d, %s, %f) seem to allow them through.

    The only way I have been able to do this is by doing my own “prepare” and then using $wpdb->query() with “INSERT INTO … “, “UPDATE …” or “REPLACE…”.

    If I have missed how to do this, please let me know. Otherwise, it would be nice to have %b for bit strings (b’xxxx’) rather than %s and also %u (or something) that does not do any quoting or processing of that replacement value (e.g., NOW(), or any MYSQL function or calculation).

Viewing 2 replies - 1 through 2 (of 2 total)
  • it just give the user databse previlage to access mysql databse

    Moderator bcworkz


    $wpdb does a lot more than give database access privilege, but it only is intended to support a small group of data types: float, integer, string. $wpdb->query() fortunately allows pretty much unfettered queries so you are saved from the need to create another connection. I believe with any other $wpdb method you will run up against data type restrictions, so you’ve probably done the only thing you could do.

    The array $wpdb->field_types looks intriguing though. Perhaps adding your column and data types here could be a workaround. Couldn’t say for sure, but may be worth experimenting with if you feel like it. See the source for wp_set_wpdb_vars() in wp-includes/load.php for background info.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Possible to use MySQL functions in insert, update, replace?’ is closed to new replies.