Support » Plugins and Hacks » Count per Day » [Plugin: Count per Day] SQL DB error

  • Resolved Simon

    (@simonwe)


    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/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Tom Braider

    (@tom-braider)


    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.

    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…

    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.

    Plugin Author Tom Braider

    (@tom-braider)


    Try this patch in counter_core.php

    function mysqlQuery( $kind = '', $sql, $func = '' )
    {
    	global $wpdb;
    	if (empty($sql)) return; // <- add this line

    Thanks but this fragment was already there:

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

    (@tom-braider)


    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;
    }

    That did the trick.
    Thanks a ton!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Count per Day] SQL DB error’ is closed to new replies.