Database query error

When I turned debug mode on, one database query error.

You have an error in your SQL syntax:
select distinct album_id from fitwp_rt_rtm_media where 2=2 AND context = ‘profile’ AND fitwp_rt_rtm_media.blog_id = ‘3’ and album_id in (,2) AND media_author=13

relevant code:

app/helper/RTMediaModel.php:
function get_other_album_count ( $profile_id, $context = “profile” ) {
$global = RTMediaAlbum::get_globals ();
$sql = “select distinct album_id from {$this->table_name} where 2=2 AND context = ‘{$context}’ “;
if ( is_multisite () ) {
$sql.= " AND {$this->table_name}.blog_id = '”.get_current_blog_id().”’ “;
}
if ( is_array ( $global ) && count ( $global ) > 0 ) {
$sql .= " and album_id in (”;
$sep = “”;
foreach ( $global as $id ) {
$sql .= $sep . $id;
$sep = “,”;
}
$sql .= “)”;
}
if ( $context == “profile” ) {
$sql .= " AND media_author=$profile_id ";
} else if ( $context == “group” ) {
$sql .= " AND context_id=$profile_id ";
}
global $wpdb;
$result = $wpdb->get_results ( $sql );
if ( isset ( $result ) ) {
return count ( $result );
} else {
return 0;
}
}

static function get_globals () {
return rtmedia_get_site_option ( ‘rtmedia-global-albums’ );
}

function rtmedia_get_site_option($option_name, $default = false) {
if( is_multisite() ) {
$return_val = get_option($option_name, $default);
if( $return_val === false ) {
$return_val = get_site_option($option_name, $default);
if( $return_val === false ) {
if( function_exists( “bp_get_option” ) ) {
$return_val = bp_get_option($option_name, $default);
}
}
rtmedia_update_site_option( $option_name, $return_val );
}
} else {
$return_val = get_site_option($option_name, $default);
if ($return_val === false) {
if (function_exists(“bp_get_option”)) {
$return_val = bp_get_option($option_name, $default);
rtmedia_update_site_option($option_name, $return_val);
}
}
}
if ($default !== false && $return_val === false) {
$return_val = $default;
}
return $return_val;
}

and I checked the database:

mysql> select * from fitwp_options where option_name=‘rtmedia-global-albums’;
±----------±----------------------±---------------±---------+
| option_id | option_name | option_value | autoload |
±----------±----------------------±---------------±---------+
| 315 | rtmedia-global-albums | a:1:{i:0;i:1;} | yes |
±----------±----------------------±---------------±---------+
1 row in set (0.00 sec)

mysql>
mysql> select * from fitwp_1_options where option_name=‘rtmedia-global-albums’;
ERROR 1146 (42S02): Table ‘fitnesshubsdb.fitwp_1_options’ doesn’t exist
mysql> select * from fitwp_2_options where option_name=‘rtmedia-global-albums’;
±----------±----------------------±----------------------------------------±---------+
| option_id | option_name | option_value | autoload |
±----------±----------------------±----------------------------------------±---------+
| 228 | rtmedia-global-albums | a:4:{i:0;i:2;i:1;i:3;i:2;i:4;i:3;i:14;} | yes |
±----------±----------------------±----------------------------------------±---------+
1 row in set (0.00 sec)

mysql> select * from fitwp_3_options where option_name=‘rtmedia-global-albums’;
±----------±----------------------±----------------------------±---------+
| option_id | option_name | option_value | autoload |
±----------±----------------------±----------------------------±---------+
| 264 | rtmedia-global-albums | a:2:{s:0:"";N;i:0;s:1:“2”;} | yes |
±----------±----------------------±----------------------------±---------+
1 row in set (0.00 sec)

Looks the problem is that one array with empty element, what could be the reason caused this? I had created albums without uploaded medias yet.

Thanks!

Can you give some more detail on which page you are facing this SQL error?

I just access the user profile and click Media tab:

[11-May-2014 02:28:43 UTC] WordPress数据库查询SELECT * FROM fitwp_3_rt_rtm_attribute_taxonomies where 2=2 ORDER BY fitwp_3_rt_rtm_attribute_taxonomies.id desc时发生Table ‘fitnesshubsdb.fitwp_3_rt_rtm_attribute_taxonomies’ doesn’t exist错误,这是由require(‘wp-blog-header.php’), require_once(‘wp-load.php’), require_once(‘wp-config.php’), require_once(‘wp-settings.php’), do_action(‘init’), call_user_func_array, RTMediaProAttributes->init_modules, RTMediaAttributesModel->get_all_attributes, RTDBModel->get查询的。

[11-May-2014 02:28:43 UTC] WordPress数据库查询select distinct album_id from fitwp_rt_rtm_media where 2=2 AND context = ‘profile’ AND fitwp_rt_rtm_media.blog_id = ‘3’ and album_id in (,2) AND media_author=1 时发生You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘2) AND media_author=1’ at line 1错误,这是由require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(’/themes/inspirebook/index.php’), get_template_part, locate_template, load_template, require(’/themes/inspirebook/loop-common.php’), the_content, apply_filters(‘the_content’), call_user_func_array, RTMediaRouter->rt_replace_the_content, load_template, require_once(’/themes/inspirebook/rtmedia/main.php’), rtmedia_sub_nav, RTMediaNav->sub_nav, RTMediaModel->get_other_album_count查询的。

as you noticed: there is also ‘fitnesshubsdb.fitwp_3_rt_rtm_attribute_taxonomies’ doesn’t exist problem.

My configuration: 1 multisite network with 1 primary site and 2 subdomain sites: the primary site is just a blog site, and buddypress + inspirebook is on one subdomain site (site id: 3):

define(‘MULTISITE’, true);
define(‘SUBDOMAIN_INSTALL’, true);
define(‘DOMAIN_CURRENT_SITE’, ‘fitnesshubs.com’);
define(‘PATH_CURRENT_SITE’, ‘/’);
define(‘SITE_ID_CURRENT_SITE’, 1);
define(‘BLOG_ID_CURRENT_SITE’, 1);

define(‘WP_DEFAULT_THEME’, ‘pinboard-child’);

/* install buddypress on child site community.fitnesshubs.com */
define ( ‘BP_ROOT_BLOG’, 3 ); // buddypress with inspirebook
define ( ‘BP_ENABLE_MULTIBLOG’, false );
define ( ‘BP_ENABLE_ROOT_PROFILES’, true );

Wordpress 3.9.1, BuddyPress 2.0.1, rtMedia 3.6.14, rtMedia PRO 2.3, rtMedia Instagram 2.1.4, rtMedia Photo Tagging 2.2.4

mysql> show tables;
±----------------------------------+
| Tables_in_fitnesshubsdb |
±----------------------------------+
| fitwp_2_commentmeta |
| fitwp_2_comments |
| fitwp_2_links |
| fitwp_2_mycred_log |
| fitwp_2_options |
| fitwp_2_p2p |
| fitwp_2_p2pmeta |
| fitwp_2_postmeta |
| fitwp_2_posts |
| fitwp_2_term_relationships |
| fitwp_2_term_taxonomy |
| fitwp_2_terms |
| fitwp_3_commentmeta |
| fitwp_3_comments |
| fitwp_3_mycred_log |
| fitwp_3_options |
| fitwp_3_p2p |
| fitwp_3_p2pmeta |
| fitwp_3_postmeta |
| fitwp_3_posts |
| fitwp_3_term_relationships |
| fitwp_3_term_taxonomy |
| fitwp_3_terms |
| fitwp_blog_versions |
| fitwp_blogs |
| fitwp_bp_activity |
| fitwp_bp_activity_meta |
| fitwp_bp_follow |
| fitwp_bp_friends |
| fitwp_bp_groups |
| fitwp_bp_groups_groupmeta |
| fitwp_bp_groups_members |
| fitwp_bp_messages_messages |
| fitwp_bp_messages_notices |
| fitwp_bp_messages_recipients |
| fitwp_bp_notifications |
| fitwp_bp_user_blogs |
| fitwp_bp_user_blogs_blogmeta |
| fitwp_bp_xprofile_data |
| fitwp_bp_xprofile_fields |
| fitwp_bp_xprofile_groups |
| fitwp_bp_xprofile_meta |
| fitwp_commentmeta |
| fitwp_comments |
| fitwp_connect_log |
| fitwp_gpi_page_blacklist |
| fitwp_gpi_page_reports |
| fitwp_gpi_page_stats |
| fitwp_links |
| fitwp_mycred_log |
| fitwp_options |
| fitwp_p2p |
| fitwp_p2pmeta |
| fitwp_popularpostsdata |
| fitwp_popularpostsdatacache |
| fitwp_postmeta |
| fitwp_posts |
| fitwp_registration_log |
| fitwp_rt_rtm_api |
| fitwp_rt_rtm_attribute_taxonomies |
| fitwp_rt_rtm_media |
| fitwp_rt_rtm_media_interaction |
| fitwp_rt_rtm_media_meta |
| fitwp_signups |
| fitwp_site |
| fitwp_sitemeta |
| fitwp_term_relationships |
| fitwp_term_taxonomy |
| fitwp_terms |
| fitwp_usermeta |
| fitwp_users |
±----------------------------------+

The " fitnesshubsdb.fitwp_3_rt_rtm_attribute_taxonomies’ doesn’t exist" error logs occurred very often when access the Activity page.

@hanzhidou,
We are looking into it. I will notify you when we figured out the problem.