PHP code example of jessecascio / querypro

1. Go to this page and download the library: Download jessecascio/querypro 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/ */

    

jessecascio / querypro example snippets




use QueryPro;
use QueryPro\Handler;

class Database
{
	private $udp;
	
	public function __construct()
	{	
		$socket    = new QueryPro\Socket('127.0.0.1', 4444);
    	$this->udp = new Handler\SQL('application-name', $socket);
	}

	/**
	 * Example updating Database wrapper class
	 */
	public function query($query) 
	{
		// other important stuff

		// track query and duration
		$start  = microtime(true);
		$result = @mysql_query( $query, $this->dbh );
		$this->udp->batch($query, $start, microtime(true)); 

		// batch send query data via UDP
		$this->udp->send();

		// continue on
	}
}



use QueryPro;
use QueryPro\Handler;

$socket  = new QueryPro\Socket('127.0.0.1', 4444);
$handler = new Handler\SQL('application-name', $socket);

// only want to track these queries in application logic
$timer = microtime(true);
$database->query('SELECT * FROM TABLE');
$handler->batch('SELECT * FROM TABLE', $timer, microtime(true)); // track duration

// ...
$timer = microtime(true);
$database->query('SELECT * FROM OTHER');
$handler->batch('SELECT * FROM OTHER', $timer, microtime(true));

// batch send query data via UDP
$handler->send();