Title: get plugin data from mysql database
Last modified: August 19, 2016

---

# get plugin data from mysql database

 *  [bjf98](https://wordpress.org/support/users/bjf98/)
 * (@bjf98)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/get-plugin-data-from-mysql-database/)
 * Hi
    I am trying to get the value of the site’s location (siteurl field) in the
   wp_options table to use in my code. Here is what I have written so far.
 *     ```
       function wp_head_intercept(){
       			global $wpdb;
       			$result = mysql_query("SELECT * FROM wordpress_options WHERE option_name='siteurl'") or die(mysql_error());
       			$row = mysql_fetch_array( $result );
       			require($row['option_value'],"wp-content/plugins/passprotect/php/pass.php");
       		}
       ```
   
 * Also, in pass.php I need to retrieve the password set for the site. (stored in
   wp_options->site_pass)
 *     ```
       include_once('../../../../wp-config.php');
       include_once('../../../../wp-includes/wp-db.php');
       global $wpdb;
       $result = mysql_query("SELECT * FROM wordpress_options WHERE option_name='site_pass'") or die(mysql_error());
       $row = mysql_fetch_array( $result );
       $row['option_value'] = $password
   
       /* Config Section */
   
       $pass		= '$password';				// Set the password.
       ```
   
 * When I view the test blog, all I see is a blank screen. Can anyone tell me what
   I’m doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [shariyaar_shah](https://wordpress.org/support/users/shariyaar_shah/)
 * (@shariyaar_shah)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-plugin-data-from-mysql-database/#post-830415)
 * the simple way is to get
 *     ```
       <?php
       global $wpdb;
   
       	$res = $wpdb->get_results("SELECT option_value FROM wp_options WHERE option_name = 'siteurl'");
       foreach ($res as $rs) {
       echo	$rs->option_value;
       }
       ?>
       ```
   
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/get-plugin-data-from-mysql-database/#post-830416)
 * you dont have to construct a query to get that info.
 * `get_option('siteurl')`
 *  [skd_sam](https://wordpress.org/support/users/skd_sam/)
 * (@skd_sam)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/get-plugin-data-from-mysql-database/#post-830426)
 * Hi shariyaar_shah,whooami
 * Im stuck trying this methord but using my own database table i cant seem to pull
   info from my table with shariyaar_shah code but works for options table.. here
   is my code what am i doing wrong ?
 *     ```
       <?php
       /*
       Plugin Name: wp-html-profile-adder
       Plugin URI: http://www.swipedstudio.com/wp_plugin/
       Description: Plugin for adding html/xhtml code at the bottom of profile page.
       Version: 0.1
       Author: Sam Miller
       Author URI: http://www.swipedstudio.com/
       */
   
       /*  Copyright 2009  Sam Miller  (email : skdsounds@hotmail.com)
   
           This program is free software; you can redistribute it and/or modify
           it under the terms of the GNU General Public License as published by
           the Free Software Foundation; either version 2 of the License, or
           (at your option) any later version.
   
           This program is distributed in the hope that it will be useful,
           but WITHOUT ANY WARRANTY; without even the implied warranty of
           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
           GNU General Public License for more details.
   
           You should have received a copy of the GNU General Public License
           along with this program; if not, write to the Free Software
           Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       */
   
       // Create a table for our plugin to hold the new/old html for profile page.
       $jal_db_version = "0.1";
       // create the tables needed or activation of plugin.
       register_activation_hook(__FILE__,'jal_install');
   
       function jal_install () {
          global $wpdb;
          global $jal_db_version;
   
          $table_name = $wpdb->prefix . "profile_adder";
          if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
   
             $sql = "CREATE TABLE " . $table_name . " (
       	  option_id mediumint(9) NOT NULL AUTO_INCREMENT,
       	  option_name text NOT NULL,
       	  option_value text NOT NULL,
       	  UNIQUE KEY id (option_id)
       	);";
   
             require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
             dbDelta($sql);
   
             $new_text = "new profile page.";
             $old_text = "old profile page.";
   
             $insert = "INSERT INTO " . $table_name .
                   " (option_name, option_value) " .
                   "VALUES ('" . $wpdb->escape('new_text') . "','" . $wpdb->escape($new_text) . "')";
   
             $results = $wpdb->query( $insert );
   
       	  $insert = "INSERT INTO " . $table_name .
                   " (option_name, option_value) " .
                   "VALUES ('" . $wpdb->escape('old_text') . "','" . $wpdb->escape($old_text) . "')";
       	  $results = $wpdb->query( $insert );
   
             add_option("jal_db_version", $jal_db_version);
   
       $installed_ver = get_option( "jal_db_version" );
   
          if( $installed_ver != $jal_db_version ) {
   
             $sql = "CREATE TABLE " . $table_name . " (
       	   option_id mediumint(9) NOT NULL AUTO_INCREMENT,
       	  option_name text NOT NULL,
       	  option_value text NOT NULL,
       	  UNIQUE KEY id (option_id)
       	);";
   
             require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
             dbDelta($sql);
   
             update_option( "jal_db_version", $jal_db_version );
         }
   
          }
       }
   
       //  adding menus to the admin panel for editing the database
       add_action('admin_menu', 'my_plugin_menu');
   
       /// adding the menu form to for the plugin
       function my_plugin_menu() {
         add_options_page('My Plugin Options', 'Profile html', 9, 'profile_adder_id', 'my_plugin_options');
       }
   
       function my_plugin_options() {
         echo '<div class="wrap">';
         echo '<h2>html for the bottom of the profile page.</h2>';
         echo '<p>This plugin allows you to add some html or text to the bottom of the profile page, I use this for help panel in proflie page and made this plugin so when i upgrade wordpress i dont have to edit the page manualy.</p><br />';
         echo '<h3>New html header for profile page.</h3>';
         echo '<form method="post"><textarea style="width: 600px;
       	height: 120px;"></textarea><br /><br /><input type="submit" name="submit" value="Submit" /></form>';
         echo '<h3>Old html header for profile page.</h3>';
         echo '<textarea style="width: 600px; height: 120px;"></textarea>';
         echo '</div>';
   
       function sample_function() {
       global $wpdb;
   
       // wordpress pull data this works !
       $res = $wpdb->get_results("SELECT option_value FROM $wpdb->options WHERE option_id = '4'");
       foreach ($res as $rs) {
       echo	$rs->option_value;
       }
       // my pull data this dont work!
       $ress = $wpdb->get_results("SELECT option_value FROM $wpdb->profile_adder WHERE option_id = '1'");
       foreach ($ress as $rss) {
       echo	$rss->option_value;
       }
   
         }
         sample_function();
       }
       ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘get plugin data from mysql database’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [password](https://wordpress.org/support/topic-tag/password/)
 * [require()](https://wordpress.org/support/topic-tag/require/)
 * [retrieve](https://wordpress.org/support/topic-tag/retrieve/)

 * 3 replies
 * 4 participants
 * Last reply from: [skd_sam](https://wordpress.org/support/users/skd_sam/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/get-plugin-data-from-mysql-database/#post-830426)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
