Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing my plugin and I am getting this error:

The plugin generated 357954 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

Now my activation hook looks like this:

    function _activate() {
    global $wpdb;
    require_once(ABSPATH . 'wp-content/plugins/my-plugin/sql.php'); 
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    dbDelta($sql); 
}

and sql.php which does import like this:

$sql .= $wpdb->query($wpdb->prepare("CREATE TABLE IF NOT EXISTS `wp_car_makes` (
  `makes_id` int(11) NOT NULL AUTO_INCREMENT,
  `makes_name` varchar(60) NOT NULL DEFAULT '',
  PRIMARY KEY (`makes_id`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=350170")); 
$sql .= $wpdb->query($wpdb->prepare("INSERT INTO `wp_car_makes`
(`makes_id`,`makes_name`) VALUES 
(1, 'Acura'), 
(2, 'Alfa Romeo'),
.... and it has a 300k+ inserts
(350169, 'Yugo');
"));

Now - everything is imported properly in DB, and plugin is working OK, it's just that this error is annoying - and I don't have white-spaces after opening/closing tags etc...

Any tips why is this happening ?

share|improve this question
2  
Best practice - don't load your plugin files with hard-coded paths. Use require_once( plugin_dir_path( __file__ ) . 'sql.php' ); –  TheDeadMedic May 8 at 9:59
    
@TheDeadMedic - You are 100% right - I've changed that ! –  Peter May 9 at 11:42

2 Answers 2

up vote 1 down vote accepted

Its not that $wpdb->query does not need $wpdb->prepare(), it's because of not using $wpdb->prepare() in a correct manner. In your case $wpdb->prepare() never received any values which it must.

Please refer to the Codex for details about using $wpdb->prepare().

share|improve this answer

OK, sorry for this, but I wasn't reading codex properly.... Anyway for all of you who have same issue query really doesn't need $wpdb->prepare() part as this is properly formatted mysql dump->[I wasn't using prepare() properly !], so query like this triggers no errors:

$sql .= $wpdb->query("CREATE TABLE IF NOT EXISTS `wp_car_makes` 
(`makes_id` int(11) NOT NULL AUTO_INCREMENT,
`makes_name` varchar(60) NOT NULL DEFAULT '',
PRIMARY KEY (`makes_id`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 
AUTO_INCREMENT=350170"); 

$sql .= $wpdb->query("INSERT INTO `wp_car_makes`
(`makes_id`,`makes_name`) VALUES 
(1, 'Acura'), 
(2, 'Alfa Romeo'),
.... and it has a 300k+ inserts
(350169, 'Yugo');
");
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.