简体   繁体   English

wordpress:全局wpdb,但未找到get_result

[英]wordpress:global wpdb but get_result not found

i have this function 我有这个功能

function get_project_id($id = 0){
          global $wpdb;
          $q = $wpdb->get_result( 'SELECT * FROM clients_projects WHERE id IN ( '.$id.' ) ' );

      return $q ;
  }

and the error was this 错误是这个

Fatal error: Call to undefined method wpdb::get_result 致命错误:调用未定义的方法wpdb :: get_result

i know this probelm because of i need wpdb as global 我知道这个原因,因为我需要将wpdb设置为全局

but it's already globaled 但已经全球化了

and when i print_r( $wpdb ) ; 当我print_r($ wpdb);

the result was this 结果是这样

 wpdb Object ( [show_errors] => [suppress_errors] => [last_error] => [num_queries] => 23 [num_rows] => 0 [rows_affected] => 0 [insert_id] => 0 [last_query] => SELECT option_value FROM wp_options WHERE option_name = 'auto_core_update_failed' LIMIT 1 [last_result] => Array ( ) [result:protected] => mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 0 [type] => 0 ) [col_info:protected] => [queries] => [reconnect_retries:protected] => 5 [prefix] => wp_ [base_prefix] => wp_ [ready] => 1 [blogid] => 0 [siteid] => 0 [tables] => Array ( [0] => posts [1] => comments [2] => links [3] => options [4] => postmeta [5] => terms [6] => term_taxonomy [7] => term_relationships [8] => commentmeta [9] => useronline ) [old_tables] => Array ( [0] => categories [1] => post2cat [2] => link2cat ) [global_tables] => Array ( [0] => users [1] => usermeta ) [ms_global_tables] => Array ( [0] => blogs [1] => signups [2] => site [3] => sitemeta [4] => sitecategories [5] => registration_log [6] => blog_versions ) [comments] => wp_comments [commentmeta] => wp_commentmeta [links] => wp_links [options] => wp_options [postmeta] => wp_postmeta [posts] => wp_posts [terms] => wp_terms [term_relationships] => wp_term_relationships [term_taxonomy] => wp_term_taxonomy [usermeta] => wp_usermeta [users] => wp_users [blogs] => [blog_versions] => [registration_log] => [signups] => [site] => [sitecategories] => [sitemeta] => [field_types] => Array ( [post_author] => %d [post_parent] => %d [menu_order] => %d [term_id] => %d [term_group] => %d [term_taxonomy_id] => %d [parent] => %d [count] => %d [object_id] => %d [term_order] => %d [ID] => %d [comment_ID] => %d [comment_post_ID] => %d [comment_parent] => %d [user_id] => %d [link_id] => %d [link_owner] => %d [link_rating] => %d [option_id] => %d [blog_id] => %d [meta_id] => %d [post_id] => %d [user_status] => %d [umeta_id] => %d [comment_karma] => %d [comment_count] => %d [active] => %d [cat_id] => %d [deleted] => %d [lang_id] => %d [mature] => %d [public] => %d [site_id] => %d [spam] => %d ) [charset] => utf8 [collate] => [dbuser:protected] => root [dbpassword:protected] => [dbname:protected] => wordpress [dbhost:protected] => localhost [dbh:protected] => mysqli Object ( [affected_rows] => 0 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 1 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.6.17 [server_version] => 50617 [stat] => Uptime: 39797 Threads: 1 Questions: 8411 Slow queries: 0 Opens: 616 Flush tables: 1 Open tables: 77 Queries per second avg: 0.211 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 344 [warning_count] => 0 ) [func_call] => $db->query("SELECT option_value FROM wp_options WHERE option_name = 'auto_core_update_failed' LIMIT 1") [is_mysql] => 1 [incompatible_modes:protected] => Array ( [0] => NO_ZERO_DATE [1] => ONLY_FULL_GROUP_BY [2] => STRICT_TRANS_TABLES [3] => STRICT_ALL_TABLES [4] => TRADITIONAL ) [use_mysqli:wpdb:private] => 1 [has_connected:wpdb:private] => 1 [categories] => wp_categories [post2cat] => wp_post2cat [link2cat] => wp_link2cat [useronline] => wp_useronline )  

but get_result not work and its 但是get_result不起作用及其

Fatal error: Call to undefined method wpdb::get_result 致命错误:调用未定义的方法wpdb :: get_result

Use $wpdb->get_results() instead of $wpdb->get_result() - you're missing the "s" at the end of the method. 使用$wpdb->get_results()代替$wpdb->get_result() -方法末尾缺少“ s”。

Additionally, you can use the following $wpdb methods that can be more useful in your case: 此外,您可以使用以下$wpdb方法,在您的情况下可能更有用:

  • get_row()
  • get_col()
  • get_var()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM