PHP code example of tpetry / php-mysql-explain

1. Go to this page and download the library: Download tpetry/php-mysql-explain library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tpetry / php-mysql-explain example snippets


use Tpetry\PhpMysqlExplain\Queries\MysqliQuery;

$mysqli = new mysqli('127.0.0.1', 'root', 'root', 'github');

$query = new MysqliQuery(
  connection: $mysqli,
  sql: 'SELECT * FROM issues',
);

$query = new MysqliQuery(
  connection: $mysqli,
  sql: 'SELECT * FROM issues WHERE type = ? AND num > ?',
  params: ['finished', 85],
);

$query = new MysqliQuery(
  connection: $mysqli,
  sql: 'SELECT * FROM issues WHERE type = ? AND num > ?',
  params: ['finished', 85],
  types: 'si',
);

use Tpetry\PhpMysqlExplain\Queries\PdoQuery;

$pdo = new PDO('mysql:host=127.0.0.1;dbname=github', 'root', 'root');

$query = new PdoQuery(
  connection: $pdo,
  sql: 'SELECT * FROM issues',
);

$query = new PdoQuery(
  connection: $pdo,
  sql: 'SELECT * FROM issues WHERE type = ? AND num > ?',
  params: ['finished', 85],
);

$query = new PdoQuery(
  connection: $pdo,
  sql: 'SELECT * FROM issues WHERE type = :type AND num > :num',
  params: ['type' => 'finished', 'num' => 85],
);

$query = new PdoQuery(
  connection: $pdo,
  sql: 'SELECT * FROM issues WHERE type = ? AND num > ?',
  params: ['finished', 85],
  types: [PDO::PARAM_STR, PDO::PARAM_INT],
);

$query = new PdoQuery(
  connection: $pdo,
  sql: 'SELECT * FROM issues WHERE type = :type AND num > :num',
  params: ['type' => 'finished', 'num' => 85],
  types: ['type' => PDO::PARAM_STR, 'num' => PDO::PARAM_INT],
);

use Tpetry\PhpMysqlExplain\Metrics\Collector;

$metrics = (new Collector())->execute($query);

use GuzzleHttp\Client as GuzzleClient;
use Tpetry\PhpMysqlExplain\Api\Client;

$client = new Client(new GuzzleClient());
$response = $client->submit($metrics);

var_dump($response->getUrl());
bash
composer