Escaping / encoding data before insert into a database?

You escape on output, what I suspect here is a confusion between escaping sanitizing and validating Sanitise when data arrives. This strips out stuff that shouldn’t be there, e.g. upper case letters in a lower case string, words and letters in a phone number, trailing spaces etc. Sanitising cleans data common sanitising functions include trim, … Read more

Query from a different database than the default

I don’t know why the mysql_connect isn’t working inside WordPress. But an easier way of doing it would be to use the $wpdb class. Try replacing your code with this: $second_db = new $wpdb( ‘user’, ‘pass’, ‘dbname’, ‘host’ ); $q = $second_db->get_results( ‘SELECT * FROM vars’ ); var_dump( $q ); and see if you get … Read more

Should I remove transients from the wp_options table?

This is not an amount that is likely to cause performance issues. However if you are concerned about leftover transients it is worth looking into if any code you are using is consistently “leaking” them (creating transients that are never removed). See Are transients garbage collected? for relevant discussion and some code snippets.

Single database for multiple instances

It’s considered best practice to have two separate databases (one for production, one for development) then migrate the database as detailed here. If you, for example, install a database-changing plugin on one but not the other, you risk breaking one of your sites until you duplicate those changes over. If you’re working late tweaking code, … Read more

update_user_meta() does not work

You set the variable $user before you created this user.. It should be like this and you need to check if the user already exists $user = get_user_by(“email”, $email); // Its return you the user object if($user) { update_user_meta($user->ID, “quiz_scores”, $score); } else { $user_id = register_new_user($email, $_SESSION[“email”]); update_user_meta($user_id, “quiz_scores”, $score); }

Does WordPress ever need multiple databases?

could a WordPress installation get so large or gain so many users that it needs another database? If you mean sharding of a database to spread data across multiple servers for sheer quantity of data, then yes, but only for 3 or 4 websites in existence, aka WordPress.com. If you think you need this for … Read more

How do I reset a self-hosted WordPress URL?

The easiest way to do this is by using copy&replace in the SQL file. Export the database. Use your favorite text editor and do a copy&replace and import it into a new database. Then you go to wp-config.php and you change the WP_HOME and WP_SITEURL to the new host. Then you change the databasename. You … Read more