Title: [Plugin: Count per Day] SQL DB error
Last modified: August 20, 2016

---

# [Plugin: Count per Day] SQL DB error

 *  Resolved [Simon](https://wordpress.org/support/users/simonwe/)
 * (@simonwe)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/)
 * 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/](http://wordpress.org/extend/plugins/count-per-day/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Tom Braider](https://wordpress.org/support/users/tom-braider/)
 * (@tom-braider)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949148)
 * 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.
 *  Thread Starter [Simon](https://wordpress.org/support/users/simonwe/)
 * (@simonwe)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949153)
 * 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…
 *  [dafi87](https://wordpress.org/support/users/dafi87/)
 * (@dafi87)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949253)
 * 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](https://wordpress.org/support/users/tom-braider/)
 * (@tom-braider)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949254)
 * Try this patch in counter_core.php
 *     ```
       function mysqlQuery( $kind = '', $sql, $func = '' )
       {
       	global $wpdb;
       	if (empty($sql)) return; // <- add this line
       ```
   
 *  [dafi87](https://wordpress.org/support/users/dafi87/)
 * (@dafi87)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949255)
 * Thanks but this fragment was already there:
 *     ```
       if (empty($sql))
          return;
       ```
   
 *  Plugin Author [Tom Braider](https://wordpress.org/support/users/tom-braider/)
 * (@tom-braider)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949256)
 * 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;
       }
       ```
   
 *  [dafi87](https://wordpress.org/support/users/dafi87/)
 * (@dafi87)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949257)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/count-per-day_d2a1c1.svg)
 * [Count per Day](https://wordpress.org/plugins/count-per-day/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/count-per-day/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/count-per-day/)
 * [Active Topics](https://wordpress.org/support/plugin/count-per-day/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/count-per-day/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/count-per-day/reviews/)

 * 7 replies
 * 3 participants
 * Last reply from: [dafi87](https://wordpress.org/support/users/dafi87/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-count-per-day-sql-db-error/#post-2949257)
 * Status: resolved