|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2020 New Relic Corporation. All rights reserved. |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/*DESCRIPTION |
| 8 | +The agent should generate explain plans when connections are made with |
| 9 | +mysqli_connect() when connecting to the database via socket. |
| 10 | +*/ |
| 11 | + |
| 12 | +/*SKIPIF |
| 13 | +<?php require("skipif.inc"); |
| 14 | +*/ |
| 15 | + |
| 16 | +/*INI |
| 17 | +error_reporting = E_ALL & ~E_DEPRECATED |
| 18 | +newrelic.transaction_tracer.explain_enabled = true |
| 19 | +newrelic.transaction_tracer.explain_threshold = 0 |
| 20 | +newrelic.transaction_tracer.record_sql = obfuscated |
| 21 | +*/ |
| 22 | + |
| 23 | +/*EXPECT |
| 24 | +STATISTICS |
| 25 | +*/ |
| 26 | + |
| 27 | +/*EXPECT_METRICS |
| 28 | +[ |
| 29 | + "?? agent run id", |
| 30 | + "?? start time", |
| 31 | + "?? stop time", |
| 32 | + [ |
| 33 | + [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]], |
| 34 | + [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]], |
| 35 | + [{"name":"Datastore/all"}, [1, "??", "??", "??", "??", "??"]], |
| 36 | + [{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]], |
| 37 | + [{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]], |
| 38 | + [{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]], |
| 39 | + [{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]], |
| 40 | + [{"name":"Datastore/statement/MySQL/tables/select", |
| 41 | + "scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], |
| 42 | + [{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]], |
| 43 | + [{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]], |
| 44 | + [{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], |
| 45 | + [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], |
| 46 | + [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], |
| 47 | + [{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], |
| 48 | + [{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]], |
| 49 | + [{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]] |
| 50 | + ] |
| 51 | +] |
| 52 | +*/ |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +/*EXPECT_SLOW_SQLS |
| 57 | +[ |
| 58 | + [ |
| 59 | + [ |
| 60 | + "OtherTransaction/php__FILE__", |
| 61 | + "<unknown>", |
| 62 | + "?? SQL ID", |
| 63 | + "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?", |
| 64 | + "Datastore/statement/MySQL/tables/select", |
| 65 | + 1, |
| 66 | + "?? total time", |
| 67 | + "?? min time", |
| 68 | + "?? max time", |
| 69 | + { |
| 70 | + "explain_plan": [ |
| 71 | + [ |
| 72 | + "id", |
| 73 | + "select_type", |
| 74 | + "table", |
| 75 | + "type", |
| 76 | + "possible_keys", |
| 77 | + "key", |
| 78 | + "key_len", |
| 79 | + "ref", |
| 80 | + "rows", |
| 81 | + "Extra" |
| 82 | + ], |
| 83 | + [ |
| 84 | + [ |
| 85 | + 1, |
| 86 | + "SIMPLE", |
| 87 | + "tables", |
| 88 | + "ALL", |
| 89 | + null, |
| 90 | + "TABLE_NAME", |
| 91 | + null, |
| 92 | + null, |
| 93 | + null, |
| 94 | + "Using where; Skip_open_table; Scanned 1 database" |
| 95 | + ] |
| 96 | + ] |
| 97 | + ], |
| 98 | + "backtrace": [ |
| 99 | + " in mysqli_stmt_execute called at __FILE__ (??)", |
| 100 | + " in test_prepare called at __FILE__ (??)" |
| 101 | + ] |
| 102 | + } |
| 103 | + ] |
| 104 | + ] |
| 105 | +] |
| 106 | +*/ |
| 107 | + |
| 108 | +/*EXPECT_TRACED_ERRORS |
| 109 | +null |
| 110 | +*/ |
| 111 | + |
| 112 | +require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php'); |
| 113 | + |
| 114 | +function test_prepare($link) |
| 115 | +{ |
| 116 | + $query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'"; |
| 117 | + |
| 118 | + $stmt = mysqli_prepare($link, $query); |
| 119 | + if (FALSE === $stmt) { |
| 120 | + echo mysqli_error($link) . "\n"; |
| 121 | + return; |
| 122 | + } |
| 123 | + |
| 124 | + if (FALSE === mysqli_stmt_execute($stmt)) { |
| 125 | + echo mysqli_stmt_error($stmt) . "\n"; |
| 126 | + return; |
| 127 | + } |
| 128 | + |
| 129 | + if (FALSE === mysqli_stmt_bind_result($stmt, $value)) { |
| 130 | + echo mysqli_stmt_error($stmt) . "\n"; |
| 131 | + return; |
| 132 | + } |
| 133 | + |
| 134 | + while (mysqli_stmt_fetch($stmt)) { |
| 135 | + echo $value . "\n"; |
| 136 | + } |
| 137 | + |
| 138 | + mysqli_stmt_close($stmt); |
| 139 | +} |
| 140 | + |
| 141 | +$link = mysqli_connect('localhost', $MYSQL_USER, $MYSQL_PASSWD, $MYSQL_DB, null, $MYSQL_SOCKET); |
| 142 | +if (mysqli_connect_errno()) { |
| 143 | + echo mysqli_connect_error() . "\n"; |
| 144 | + exit(1); |
| 145 | +} |
| 146 | + |
| 147 | +test_prepare($link); |
| 148 | +mysqli_close($link); |
0 commit comments