I wouldn’t use a PHP file on my server. I’d use the copy of phpMyAdmin that’s set up on my hosting account. If you don’t have that you could set up a small page that has a DB connection and a form and will run any SQL that’s in the form when you submit it. Just be sure that if you do that, that you remove that as soon as you are finished with it – you don’t want anyone else accidentally finding it and having direct access to your DB.
Just for fun, taking your question at face value. This is far from efficient, nor convenient, but it is quick and dirty, the file itself is quite short, and it’s in keeping with the WP topics here 🙂
<?php
require_once('wp-load.php');
print_r($wpdb->get_results(
"Insert your test query here and upload before loading page"
));
Seriously though, +1 for using phpMyAdmin.
Wonderful! Quick and easy!!
And it lets me test my SQL in a WP context, rather than just a purely SQL context (ie “SELECT … FROM $wpdb->posts…” rather than “SELECT … FROM wp_posts…”).
There’s a time and a place for each, of course. And now I’ve got a way to do each.
Thanks, bcworkz!!
Here it is again, with a slight tweak to improve readability of the result, and with a sample SQL statement in place.
<pre>
<?php
require_once('wp-load.php');
print_r($wpdb->get_results(
"SELECT $wpdb->posts.post_title, $wpdb->posts.ID,
$wpdb->posts.post_date
FROM $wpdb->posts
WHERE $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
ORDER BY $wpdb->posts.post_date DESC"
));
?>
</pre>