• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

mysql

wpdb insert returning false

October 14, 2017 by Webhead

Problem

When running wpdb->insert the result returns false.  All the values seem to check out to be fine.

 

Solution

The problem might be due to this bug in WordPress.  Basically one of your fields is too long and WordPress is not completing the insert.  Reading through the ticket, it seems it is a WordPress error and not a MySql error so it would be pretty difficult to go through all the fields, determine the column field size limits, and then return an error of some sort.  Anyway, this is one possible reason to wpdb->insert returning false.

Filed Under: Coding Tagged With: mysql, wordpress

Where is wp_capabilities?

October 5, 2017 by Webhead

Problem

After creating a user with a certain role I need to do a custom sql query where it only selected users of a specific role.  This failed to find anything:

select u.ID, u.display_name, u.user_login
from $wpdb->users as u
inner join $wpdb->usermeta as umr
on ( umr.user_id = u.ID )
and ( umr.meta_key = 'wp_capabilities' )

$user = get_userinfo( $user_id );
var_dump( $user->roles );

get_userinfo got the right role, so saving was correct.

$caps = get_user_meta( $user_id, 'wp_capabilities' );
var_dump( $caps );

$caps was null.  weird.

 

Solution

You learn something new everyday.  After looking through the WordPress core code I found that the meta key is actually composed of the table prefix and ‘capabilities’.  So the correct query would be:

select u.ID, u.display_name, u.user_login
from $wpdb->users as u
inner join $wpdb->usermeta as umr
on ( umr.user_id = u.ID )
and ( umr.meta_key = '" . $wpdb->prefix . "capabilities' )

Filed Under: Coding Tagged With: mysql, php, wordpress

Speed up WP_Query

January 29, 2016 by Webhead

In WordPress, when a query does not need paging and you only want a limited amount of results, like the last 5 posts, set the ‘no_found_rows’ parameter to true.  This prevents WordPress from doing additional work in counting the total matched rows, thus speeding up your query.

This is already built into get_posts, but not WP_Query.

Example:

$last_5_query = WP_Query( array( ‘no_found_rows’=> true, ‘posts_per_page’=>5 ) );

Filed Under: Coding Tagged With: mysql, optimize, wordpress

Migrating Multisite to Single Site

April 18, 2014 by Webhead

I needed to migrate a site on a multisite installation to a single installation.  This article did the trick for the most part.

 

http://beacon.wharton.upenn.edu/404/2011/02/the-return-from-multisite/

Filed Under: Coding Tagged With: mysql, wordpress

WordPress “The plugin generated xxxx characters of unexpected output during activation”

September 11, 2012 by Webhead

Problem

I was developing a plugin for wordpress and receive a messsage:

The plugin generated 496 characters of unexpected output during activation

Solution

I placed the following code at the end of my plugin file,

update_option(‘plugin_error’,  ob_get_contents());

then looked in the wordpress options table using the query

“SELECT *
FROM `wp_options`
WHERE option_name = ‘plugin_error'”

Then I could see what the unexpected output was.

Or I could’ve installed the WH Debug plugin and just added this to the end of the plugin file:

wh_debug( ‘plugin_error’, ob_get_contents());

And then viewed it in the WordPress admin pages under Tools->WH Debug.

 

source: http://hungrycoder.xenexbd.com/wordpress-2/how-i-have-solved-the-the-plugin-generated-xxxx-characters-of-unexpected-output-during-activation-problem.html

keywords: wordpress characters of unexpected output during activation

 

Filed Under: Coding Tagged With: debug, mysql, php, wordpress

MAMP – MySQL can’t connect after OS X Crash

September 4, 2012 by Webhead

Problem

I had my macbook open, it went to sleep and I couldn’t wake it up.  After holding down the powerbutton for over 10 seconds, it turned on.  Everything was fine until I tried to open the MAMP home page.  MySQL couldn’t start.  the error logs showed:

InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
120904 14:51:31 InnoDB: Unable to open the first data file
InnoDB: Error in opening ./ibdata1

Solution

Solution is to find the mysqlid process and end it.  Then restart MAMP and things should be good to go.  more details on this great post:

http://aralbalkan.com/1931

 

Another Problem

When visiting phpMyAdmin you get the following errors:

“Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.”

Another Solution

Clear your browser cache.

thanks to: http://stackoverflow.com/questions/5013118/cannot-start-session-without-errors-in-phpmyadmin

 

 

keywords: mamp check that you do not already have another mysqlid process

Filed Under: Server Stuff Tagged With: apache, linux, mac os x, mysql

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to Next Page »

Primary Sidebar

Topics

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools