Last active
August 7, 2019 23:04
-
-
Save saiberz/81558f951c567eb8a9249bea48eac4be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function createConn($options){ | |
$host = $options["host"]; | |
$user = $options["user"]; | |
$pass = $options["pass"]; | |
$db = $options["db"]; | |
$uri = 'mysql:host=' . $host . ';dbname=' . $db; | |
return new PDO($uri, $user, $pass); | |
} | |
function _runQuery($conn, $query){ | |
$pdo_query = $conn->query($query); | |
return $pdo_query->fetchAll(PDO::FETCH_ASSOC); | |
} | |
function runQuery($conn, $query, $vars){ | |
$pdo_query = $conn->prepare($query); | |
$pdo_query->execute($vars); | |
return $pdo_query->fetchAll(); | |
} | |
function profileQuery($conn, $query, $vars){ | |
// runQuery($conn, "set profiling = 1", []); | |
$result = runQuery($conn, $query, $vars); | |
$profile = runQuery($conn, "show profiles", []); | |
$time = $profile[0]["Duration"]; | |
runQuery($conn, "set profiling = 0", []); | |
return [ | |
// "result" => $result, | |
"profile" => $profile, | |
"query" => $query, | |
"time" => $time | |
]; | |
// return $result; | |
} | |
$options = [ | |
"host" => "127.0.0.1", | |
"user" => "root", | |
"pass" => "root", | |
"db" => "" | |
]; | |
$conn = createConn($options); | |
runQuery($conn, "SET profiling = 1", []); | |
runQuery($conn, "SET profiling_history_size = 100", []); | |
$query = "select * from alerts"; | |
for($i = 0; $i < 100; $i++){ | |
$result = runQuery($conn, $query, []); | |
} | |
$result = runQuery($conn, "show profiles", []); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment