Category Archives: sql

SQL to get WooCommerce product categories (terms)

For an import script I needed to get WooCommerce product categories so I ended up looking the generated query in /var/log/mysql/query.log for get_the_terms($postID, ‘taxonomy_name’) I ended up using the following SQL query to get product categories: SELECT t.*, tt.* FROM … Continue reading

Posted in mysql, sql, Uncategorized, woocommerce, wordpress | Tagged , , , , | Leave a comment

Getting ‘doesn’t have a default value’ from MySQL (MariaDB)?

Solution for me from ideas at https://stackoverflow.com/questions/15438840/mysql-error-1364-field-doesnt-have-a-default-values and https://www.farbeyondcode.com/Solution-for-MariaDB-Field–xxx–doesn-t-have-a-default-value-5-2720.html was to remove ‘STRICT_TRANS_TABLES’ from my.cnf. So I ended up with the following in /usr/local/mysql/my.cnf: [mysqlnd] sql_mode=NO_ENGINE_SUBSTITUTION

Posted in osx, sql | Tagged , | Leave a comment

REPLACE instead of SELECT and then INSERT or UPDATE

It’s nice that MySQL has the replace query so instead SELECTing to check if the data exists in the DB and than INSERTing or UPDATEing I just need to write one query. So instead this: $q = “SELECT id FROM … Continue reading

Posted in sql | Leave a comment