WordPress.org

Ready to get started?Download WordPress

Forums

Count per Day
[resolved] SQL DB error (8 posts)

  1. Simon
    Member
    Posted 1 year ago #

    Hi,

    Thanks for a fine plugin!

    the only problem I have is that I constantly receive to following error:

    [Aug 06, 22:12:26]  WordPress database error Query was empty for query  made by CountPerDay->count, CountPerDayCore->mysqlQuery
    Aug 06, 22:13:36]  WordPress database error Query was empty for query  made by require('wp-blog-header.php'), wp, WP->main, do_action_ref_array, call_user_func_array, CountPerDay->count, CountPerDayCore->mysqlQuery

    Please fix this issue,
    If I can help in any way tell me.

    Thanks,
    Simon

    http://wordpress.org/extend/plugins/count-per-day/

  2. Tom Braider
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Simon,
    do you have the newest version of the plugin 3.2.2?
    An empty query should not find the way from the plugin to the wordpress DB function.

  3. Simon
    Member
    Posted 1 year ago #

    Yup, using the latest version 3.2.2 as you stated...
    If I can help solve this issue please tell me.
    I receive many errors like this every day...

  4. dafi87
    Member
    Posted 1 year ago #

    Same problem here.
    We are using the latest version 3.2.5.
    Is there a fix? Can we do anything?
    There are 2 wordpress systems running on the same server and only one is causing these errors. They use different databases for sure.

  5. Tom Braider
    Member
    Plugin Author

    Posted 1 year ago #

    Try this patch in counter_core.php

    function mysqlQuery( $kind = '', $sql, $func = '' )
    {
    	global $wpdb;
    	if (empty($sql)) return; // <- add this line
  6. dafi87
    Member
    Posted 1 year ago #

    Thanks but this fragment was already there:

    if (empty($sql))
       return;
  7. Tom Braider
    Member
    Plugin Author

    Posted 1 year ago #

    oh, sorry. here is my newest version of the function. just work in progress but it should work. i think the problem is an empty $preparedSql in case of an error.

    function mysqlQuery( $kind = '', $sql, $func = '' )
    {
    	global $wpdb;
    	if (empty($sql))
    		return;
    	$t = microtime(true);
    	$con = $wpdb->dbh;
    	if ( is_array($sql) )
    	{
    		$sql = array_shift($sql);
    		$args = $sql;
    		$preparedSql = $wpdb->prepare($sql, $args);
    	}
    	else
    		$preparedSql = $sql;
    	if (empty($preparedSql))
    		return;
    	$r = false;
    	if ($kind == 'var')
    		$r = $wpdb->get_var( $preparedSql );
    	else if ($kind == 'count')
    	{
    		$r = $wpdb->get_var('SELECT COUNT(*) FROM ('.trim($preparedSql,';').') t');
    	}
    	else if ($kind == 'rows')
    	{
    		$r = $wpdb->get_results( $preparedSql );
    	}
    	else
    		$wpdb->query( $preparedSql );
    	if ( $this->options['debug'] )
    	{
    		$d = number_format( microtime(true) - $t , 5);
    		$m = sprintf("%.2f", memory_get_usage()/1048576).' MB';
    		$error = (!$r && mysql_errno($con)) ? '<b style="color:red">ERROR:</b> '.mysql_errno($con).' - '.mysql_error($con).' - ' : '';
    		$this->queries[] = $func." : <b>$d</b> - $m<br/><code>$preparedSql</code><br/>$error";
    		$this->queries[0] += $d;
    	}
    	return $r;
    }
  8. dafi87
    Member
    Posted 1 year ago #

    That did the trick.
    Thanks a ton!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.