1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
<?php
$hostname = $argv[1];
$port = $argv[2];
$username = $argv[3];
$password = $argv[4];
$with_ssl = $argv[5] == "0" ? false : true;
$with_sharing = $argv[6] == "0" ? false : true;
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_init();
mysqli_real_connect($mysqli,
$hostname, $username, $password, "", $port, NULL,
$with_ssl ? MYSQLI_CLIENT_SSL : 0);
function result_as_array($res) {
if (is_bool($res)) return $res;
$rows = [];
while($row = $res->fetch_array(MYSQLI_NUM)) {
$rows[] = $row;
}
return $rows;
}
function query($m, $qry) {
return result_as_array($m->query($qry));
}
foreach ([
"DO 1",
"SELECT 1",
"SELECT 1, 1",
"SELECT 1, ?",
] as $qry) {
print("# prepare: " . $qry . "\n\n");
$stmt = $mysqli->prepare($qry);
{
print("## SHOW WARNINGS\n\n");
$warn_res = query($mysqli, "SHOW WARNINGS");
count($warn_res) == 0 or throw new Exception("expected row-count == 0, got " . count($warn_res));
}
print("## -> execute (1)\n\n");
$foo = "abc";
if ($stmt->param_count > 0) {
$stmt->bind_param("s", $foo);
}
$stmt->execute();
$res = result_as_array($stmt->result_metadata() ? $stmt->get_result() : true);
print(json_encode($res, JSON_PRETTY_PRINT) . "\n\n");
{
print("## SHOW WARNINGS\n\n");
$warn_res = query($mysqli, "SHOW WARNINGS");
count($warn_res) == 0 or throw new Exception("expected row-count == 0, got " . count($warn_res));
}
print("## -> execute (2)\n\n");
$stmt->execute();
$res = result_as_array($stmt->result_metadata() ? $stmt->get_result() : true);
print(json_encode($res, JSON_PRETTY_PRINT) . "\n\n");
{
print("## SHOW WARNINGS\n\n");
$warn_res = query($mysqli, "SHOW WARNINGS");
count($warn_res) == 0 or throw new Exception("expected row-count == 0, got " . count($warn_res));
}
$stmt->close();
}
|