mysqli + xdebug breakpoint after closing statement result in many warnings

前端 未结 6 2057
生来不讨喜
生来不讨喜 2020-11-30 07:24

I have a piece of code like this:

$conn = new mysqli($host, $username, $passwd, $dbname);

...

$stmt = $conn->prepare(\'SELECT ...\');
$stmt->bind_par         


        
6条回答
  •  旧巷少年郎
    2020-11-30 08:06

    What Alan wants to state is, that you can use these snippets the following way:

    $stmt = $conn->prepare('SELECT ...');
    $stmt->bind_param(...);
    $stmt->execute();
    $stmt->bind_result(...);
    while($stmt->fetch())
    {
        // do something here
    }
    
    // Disable the buggy interconnection between xDebug and PHP/MySQLi for a certain period
    if (function_exists('xdebug_disable'))
                  {
                   $errorlevel=error_reporting();
                   $displayerrors=ini_get('display_errors');
                   ini_set('display_errors',0);
                    error_reporting(0);
                    xdebug_disable();
                  }
    
    $stmt->close();
    unset($stmt);
    unset($conn);
    
    // finalle bring back the functionality
    if (function_exists('xdebug_enable'))
                  {
                    xdebug_enable();
                    error_reporting($errorlevel);
                   ini_set('display_errors',$displayerrors);
                  }
    

    For me this also worked in PHP 5.6 And I use it as a workaround in https://github.com/joshcam/PHP-MySQLi-Database-Class

    like so in MSQLiDB.php -> _dynamicBindResults():

    /* BUG http://stackoverflow.com/questions/25377030/mysqli-xdebug-breakpoint-after-closing-statment-result-in-many-warnings 
               temporarily disable the buggy module interconnection         */
            if (function_exists('xdebug_disable'))
                  {
                   $errorlevel=error_reporting();
                   $displayerrors=ini_get('display_errors');
                   ini_set('display_errors',0);
                    error_reporting(0);
                    xdebug_disable();
                  }
            /* Returning to normal xDebugging is only possible after $this->_mysqli->close
            if (function_exists('xdebug_enable'))
                  {
                    xdebug_enable();
                    error_reporting($errorlevel);
                   ini_set('display_errors',$displayerrors);
                  }
             * 
             */
            $stmt->close();
    

    Please note that I actually cannot reenable the xDebugging immediatly because this library destructs the MySQLi object very late. But that seems to be no reason for the debugger to stop showing debugging information :-> I had no time yet to figure out why.

提交回复
热议问题