correct sql query

You should use prepare only when you’re using SQL query – this function takes query and params and returns a safe SQL query filled with given params. Its result is a SQL query. So you can (and should) use it whenever you’re creating a SQL query and put some params in it. With $wpdb->delete or … Read more

correct validate and sql query

What you’re doing is safe. However, some notes: See the WP_User_Query class in the Codex. This is the, “official,” way to do something like this, although you’ll get an integer-indexed array of WP_User objects. Instead of the ARRAY_A that you’ve specified. You probably don’t want _my_table, unless your table is called something like wp__my_table (note … Read more

Speeding SQL queries for a large database?

Your log shows that MySQL is performing a linear scan of all table records to get the necessary row – this is because there is no index for guid Assuming wp_rb_posts is just the normal posts table with a slightly modified prefix, then you can just add an index for that field, and you’ll see … Read more

List recent 25 blogs across the network

You just have to modify your query to get only first 25 matches SELECT * FROM $wpdb->blogs WHERE spam = ‘0’ AND deleted = ‘0’ and archived = ‘0’ and public=”1″ limit 25. The result is already order by id what is incremented automatically, you don’t have anything to bother about there. Also please note, … Read more

SQL Query in WordPress – Getting Impossible WHERE error

Look at your conditions: WHERE ( ( (meta_key=’user_school_subjects’ AND meta_value LIKE ‘%history%’) OR (meta_key=’user_professional_courses’ AND meta_value LIKE ‘%history%’) OR (meta_key=’user_language_tutoring’ AND meta_value LIKE ‘%history%’) OR (meta_key=’user_music_tutoring’ AND meta_value LIKE ‘%history%’) ) AND (meta_key=’user_gender’ AND meta_value=”male”)) There is no way that you can have a meta key matching one of these– user_school_subjects, user_professional_courses, user_language_tutoring, user_music_tutoring … … Read more

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