0

Doing wordpress plugin development, I am creating a table (while installing the plugin) with the following string:

$sql = "CREATE TABLE (query skipped)..."; /*someting*/

For example: I have this

register_activation_hook( __FILE__, 'my_plugin_install' );
function my_plugin_install(){

$sql = "CREATE TABLE (query skipped)..."; /*someting*/
echo $sql;
}

The problem is there is some error with this query and and I want to see the output of $sql using php.

But the above code doesn't echo anything when plugin is installed. Any way to see the ouput?

Details: 
function my_plugin_install(){

   global $wpdb, $current_user;;

   //getting the musician/user rating keys
    global $k11, $k12, $k13, $k14, $k21, $k22, $k23, $k24;

   $fabprofile_table_name=$wpdb->prefix."fabulous_profile";

   $fabulous_profile_version = "2.0";

   //mid= music user id
   //uid = general user id
   //creating the ratings table
   $sql = "CREATE TABLE $fabprofile_table_name (

  mid tinyint(9) NOT NULL,

  uid tinyint(9) NOT NULL,

  $k11 tinyint(1) NOT NULL, $k12 tinyint(1) NOT NULL,$k13 tinyint(1) NOT NULL, $k14 tinyint(1) NOT NULL,

  $k21 tinyint(1) NOT NULL, $k22 tinyint(1) NOT NULL, $k23 tinyint(1) NOT NULL, $k24 tinyint(1) NOT NULL

);";



   require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

   dbDelta( $sql );
   $wpdb->show_errors(); 
    echo $sql;
    }

1 Answer 1

0

You could insert a

$wpdb->show_errors(); 

to output the errors in your query.

Also you need to input that sql into

dbDelta($sql)

did you miss that?

13
  • I am running the $sql query with this: dbDelta( $sql ); It doesn't help :(.. Commented Jul 3, 2014 at 5:49
  • No output with the show_errors()? Also the debug is set to true right? Commented Jul 3, 2014 at 5:51
  • nope, I don't see any output. It just shows The plugin generated ** characters of unexpected output during activation. Is there any way to see that unexpectedd output? Commented Jul 3, 2014 at 5:53
  • Did you put a global $wpdb; before your query? And also, did you include wp-admin/includes/upgrade.php ? Commented Jul 3, 2014 at 5:55
  • yes,let me show youy Commented Jul 3, 2014 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.