See output of a sql query while plugin installation in wordpress

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

Read More
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?

Related posts

Leave a Reply

2 comments

  1. It’s not possible to see the echo output, as the activation hook runs and refreshes the page. Two options:

    1. Die:

      function my_plugin_install(){
          $sql = "CREATE TABLE (query skipped)..."; 
          wp_die( $sql );
      }
      
    2. Log to file

      function my_plugin_install(){
          $sql = "CREATE TABLE (query skipped)..."; 
          $error_dir = '/Applications/MAMP/logs/php_error.log';
          error_log( $sql, 3, $error_dir );
      }
      
  2. Did you define the plugin header at the top of the file? Try to use the code like this and activate the plugin you will see the error in the admin panel.

    <?php 
    /*
    Plugin Name: Your Plugin name goes here
    Description: Brief description about your plugin.
    Author: Plugin Author name 
    Version: 1.6
    
    */
    
    function my_plugin_install(){
    
    $sql = "CREATE TABLE (query skipped)..."; /*someting*/
    echo $sql;
    }
    
    register_activation_hook( __FILE__, 'my_plugin_install' );
    ?>