Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration with mysqli #326

Open
Geethikamanat opened this issue Mar 31, 2017 · 4 comments
Open

integration with mysqli #326

Geethikamanat opened this issue Mar 31, 2017 · 4 comments

Comments

@Geethikamanat
Copy link

Geethikamanat commented Mar 31, 2017

i am using mysqli not pdo, how to integrate this with mysqli?
i am saving queries in function
function dbquery($sql) {

$msc = microtime(true);
$result = mysqli_query($GLOBALS["link"], $sql);
$msc = microtime(true)-$msc; 
$duration =  ($msc )  ;  //seconds 
$query[] = $sql.'----'.$duration;  

return $result;
}

and added a mysql collector
call collector using

$collector = new mysqlCollector($query); 
$debugbar->addCollector($collector);

but it doesnt includes ajax queries. for ajax requests i set
$debugbar->sendDataInHeaders(true);
but it doesnt works
collector

namespace DebugBar\Bridge;
use DebugBar\DataCollector\AssetProvider;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use DebugBar\DebugBarException;

class mysqlCollector extends DataCollector implements Renderable, AssetProvider
{
protected $mysql_queries;

public function __construct($mysql_queries)
{
    $this->mysql_queries = $mysql_queries; 
}

public function collect()
{  
    $queries = array();
    $totalExecTime = 0;
    foreach ($this->mysql_queries as $q) {  
        
        $query = explode('----',$q); 
        $queries[] = array(
            'sql' => $query[0],
            'duration' => $query[1],
            'duration_str' => $this->formatDuration($query[1])
        );
        $totalExecTime += $query[1];
    } 
    return array(
        'nb_statements' => count($queries),
        'accumulated_duration' => $totalExecTime,
        'accumulated_duration_str' => $this->formatDuration($totalExecTime),
        'statements' => $queries
    );
}

public function getName()
{
    return 'mysql_queries';
}

public function getWidgets()
{
    return array(
        "database" => array(
            "icon" => "arrow-right",
            "widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
            "map" => "mysql_queries",
            "default" => "[]"
        ),
        "database:badge" => array(
            "map" => "mysql_queries.nb_statements",
            "default" => 0
        )
    );
}

public function getAssets()
{
    return array(
        'css' => 'widgets/sqlqueries/widget.css',
        'js' => 'widgets/sqlqueries/widget.js'
    );
}
public function query($statement)
{
    return $this->profileCall('query', $statement, func_get_args());
}
protected function profileCall($method, $sql, array $args)
{

        $result = call_user_func_array(array($this->mysql_queries, $method), $args);print_r($result);
   
    return $result;
}
  public function addExecutedStatement( $stmt)
{
    $this->mysql_queries = $stmt; 
}

}

@devnix
Copy link

devnix commented Dec 24, 2018

Are you sure you are calling $debugbar->sendDataInHeaders(true); at the end of the script, just before echoing any output? I've fall in that little pit a few moments ago, I feel the name or the behavour of that function confusing (and not documented).

@garbinmarcelo
Copy link

Hello, I have a legacy project (PHP 5) that uses Kohana v2 and would like to know how can I log the SQL? Could help? Thanks

@ihlassovbetov
Copy link

i also have custom php framework which is made by procedural php mainly. I added PHP DebugBar, except database it works. For Database tab, I did custom mysqli collector, although it does not procude error, it does not work. Can you make an official example for mysqli integration @maximebf ? I have tried to catch queries with "$this->mysqli->query("SHOW FULL PROCESSLIST");"

@parallels999
Copy link
Contributor

parallels999 commented Mar 4, 2024

I did custom mysqli collector, although it does not procude error, it does not work

@ihlassovbetov hi, share your progress and maybe we can review why it is not working for you, an official PR could be made

Also, ideas
#517 (comment),
#213,
Collectors/DatabaseMySqliQueryCollector.php#L58
DataCollector/MysqlCollector.php#L37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants