query of the WP database from non-WP .php page
-
I am trying to create A NON-WORDPRESS PAGE that accesses the wp_users table in the WordPress database and simply have it output a very simple list of all users for me. Here’s the ultra basic code I wrote:
<? $db = mysql_connect("localhost", "DATABASE_USER", "PASSWORD"); mysql_select_db("DATABASE_NAME",$db); $query = "SELECT * FROM wp_users ORDER BY user_login"; $result = mysql_query ($query); if (@mysql_num_rows($result)) { print "<table border=\"2\">\n"; print "<tr> <td>User Name</td> <td>Email</td> <td>URL</td> </tr>\n"; print "<tr>\n"; print "<td>".$row['user_login']."</td>\n"; print "<td>".$row['user_email']."</td>\n"; print "<td>".$row['user_url']."</td>\n"; print "</tr>\n"; print "</table>\n"; } else { echo "<p>Sorry, no records were found!</p>"; } ?>
I used a similar code for a different non-WordPress site and it worked fine. But I tried this (on the same domain, same server, outside of WP) and it doesn’t work. It does not give me any error message at all so it seems to be connecting to the database fine. It displays the top row which is only the header titles of User Name, Email, and URL, but then that’s it. It isn’t giving me any additional rows or any data from the database at all. It also isn’t displaying the message “Sorry, no records were found!” either.
I’m 100% sure I have the right database name, user name, and password (which is supported by the fact that I get no error messages). It shouldn’t get much simpler than the stripped-down code I’m trying to use, so does anybody know what I’m doing wrong here?
Thanks.
- The topic ‘query of the WP database from non-WP .php page’ is closed to new replies.