how to execute different sql query in non-sanitized $wpdb->get_results function

if $wpdb->get_results is not sanitized by core code, why we can’t execute different SQL query in it? Because the wpdb class uses (see wpdb::_do_query() ) mysqli_query() (by default) or mysql_query(), and unfortunately these functions do not support multiple queries such as SELECT <query>; INSERT <query>; SELECT <query>. Therefore, if you want to execute multiple SQL … Read more

Most effective use of DB querys

The $wpdb object is based on ezSQL, it does not add much overhead, so I would not worry about that. Opening a second connection to the database yourself will probably lead to more overhead than using the $wpdb functions. The three queries you have described are ideal queries to do in the database (a small … Read more

Database slowdown after update to 3.4.1

If you’ve got 60,000 records, try cleaning post/page revisions; these really accumulate and cause excessively long queries. I’ve seen database sizes drop 90% with huge increases in performance. Run the query below in phpmyadmin or from the command line and then optimize: DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) … Read more

Creating a Front-end based User Search

As you haven’t offered the details on what you’re after, I’ll try to grab them all very briefly. Use the API – public WP_User_Query API functions Basically get_user_by() should be enough for you. Let’s say you fire of your form and the input field name was user_id. So you’d just retrieve the value from the … Read more

How to pass NULL in where array for $wpdb->update

My simple and quick solution is the use of a normal $wpdb->query() function: $wpdb->query( $wpdb->prepare(“UPDATE $schedule_table SET rpt = %s WHERE post_id = %d AND start IS NULL AND end IS NULL”, $event_tag, $post_ID ) );

How to execute mulitple statement SQL queries using $wpdb->query?

TL;DR This is not possible with wpdb. Use dbDelta(). Even better, use something else to run raw queries. Explanation wpdb->query() uses the mysql_query() function. From PHP manual: mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that’s associated with the specified link_identifier. In order for that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)