1--TEST--
2mysqli_stmt_attr_get()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    require('table.inc');
13
14    $valid_attr = array(
15        "max_length" => MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH,
16        "cursor_type" => MYSQLI_STMT_ATTR_CURSOR_TYPE,
17        "prefetch_rows" => MYSQLI_STMT_ATTR_PREFETCH_ROWS,
18    );
19
20    $stmt = mysqli_stmt_init($link);
21    mysqli_stmt_prepare($stmt, 'SELECT * FROM test');
22
23    try {
24        mysqli_stmt_attr_get($stmt, -100);
25    } catch (\ValueError $e) {
26        echo $e->getMessage() . \PHP_EOL;
27    }
28
29    foreach ($valid_attr as $k => $attr) {
30        /* This can't happen anymore as it only returns int */
31        if (false === ($tmp = mysqli_stmt_attr_get($stmt, $attr))) {
32            printf("[006] Expecting any type, but not boolean/false, got %s/%s for attribute %s/%s\n",
33                gettype($tmp), $tmp, $k, $attr);
34        }
35    }
36
37    $stmt->close();
38
39    foreach ($valid_attr as $k => $attr) {
40        try {
41            mysqli_stmt_attr_get($stmt, $attr);
42        } catch (Throwable $exception) {
43            echo $exception->getMessage() . "\n";
44        }
45    }
46
47    mysqli_close($link);
48    print "done!";
49?>
50--CLEAN--
51<?php
52    require_once("clean_table.inc");
53?>
54--EXPECT--
55mysqli_stmt_attr_get(): Argument #2 ($attribute) must be one of MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE
56mysqli_stmt object is already closed
57mysqli_stmt object is already closed
58mysqli_stmt object is already closed
59done!
60