I need to query the aMember Pro database, am_user table, from within my WordPress functions.php file. Does anyone know if WordPress has any built-in ways to query an external database? Or does someone have a brief bit of code to get me started? Thanks.
I have a WordPress page created for each of our members (who are artists). My function uses the title of the page (which is the member's name) to query the WordPress users table to get the member's username. Then the member's username is used to query the aMember database to retrieve the member's information so it can be displayed on their WordPress page. This function is in my WordPress functions.php file. function show_member() { global $wpdb; $usertitle = get_the_title(); $aUsersID = $wpdb->get_col("SELECT $wpdb->users.ID FROM $wpdb->users WHERE display_name='" . $usertitle . "'"); foreach ($aUsersID as $iUserID) : $user = get_userdata($iUserID); $userlogin = $user->user_login; $link = mysql_connect('aMember Pro database host name', 'db username', 'db password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('db name'); $query = sprintf("SELECT * FROM am_user WHERE login='%s'", mysql_real_escape_string($userlogin)); $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<strong>" . $row['name_f'] . " " . $row['name_l'] . "</strong>"; if($row['business_name']) echo "<br />" . $row['business_name']; echo "<br />" . $row['street']; echo "<br />" . $row['city'] . ", " . $row['state'] . " " . $row['zip']; echo "<br />" . $row['phone']; echo "<br />" . $row['email']; echo "<br /><a href=" . $row['website'] . ">" . $row['website'] . "</a>"; echo "<p>" . $row['biography'] , "</p>"; } mysql_free_result($result); mysql_close($link); endforeach;