MySQL crashed because of the large number of requests

MySQL shouldn’t crash because of queries like those, but it could feel like it does because your site won’t work. I’d first run SELECT option_name, length(option_value) FROM wp_options WHERE autoload = ‘yes’ ORDER BY length(option_value) DESC; to see if some option has accumulated a large value (I’ve seen wp-cron entries grow very large in one … Read more

How can i create a WooCommerce product programatically or using sql query?

This will give you a base to start: function generate_simple_product() { $name=”My Product Name”; $will_manage_stock = true; $is_virtual = false; $price = 1000.00; $is_on_sale = true; $sale_price = 999.00; $product = new \WC_Product(); $image_id = 0; // Attachment ID $gallery = self::maybe_get_gallery_image_ids(); $product->set_props( array( ‘name’ => $name, ‘featured’ => false, ‘catalog_visibility’ => ‘visible’, ‘description’ => … Read more

Converting MYSQL to WordPress $WPDB

The root problem here is the assumption that WordPress deals in mysql functions and mysql objects, and that knowledge of these functions is helpful. The truth is, this is a complete API in of itself, and so the assumptions that knowledge of mysql_ functions provides are not useful or relevant beyond the syntax of SQL. … Read more

Ajax $wpdb not returning table data

The main problem, I see in your code, is that you use query method of wpdb and assume that it is PDO statement object… But it is not. Take a look at wpdb Codex: https://codex.wordpress.org/Class_Reference/wpdb query method is used to run custom queries on DB – that’s all. What you want to use is get_results. … Read more

How to convert objects into arrays

$wpdb->get_results has a second parameter that lets you specify what kind of return value you want: For example: $data = $wpdb->get_results( $query, ARRAY_A ); Here you get an associative array back.