xref: /PHP-7.4/ext/mysqli/tests/060.phpt (revision e3e67b72)
1--TEST--
2mysqli_fetch_object with classes
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    class test_class {
13        function __construct($arg1, $arg2) {
14            echo __METHOD__ . "($arg1,$arg2)\n";
15        }
16    }
17
18    /*** test mysqli_connect 127.0.0.1 ***/
19    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
20
21    mysqli_select_db($link, $db);
22    mysqli_query($link, "SET sql_mode=''");
23
24    mysqli_query($link,"DROP TABLE IF EXISTS test_fetch");
25    mysqli_query($link,"CREATE TABLE test_fetch(c1 smallint unsigned,
26        c2 smallint unsigned,
27        c3 smallint,
28        c4 smallint,
29        c5 smallint,
30        c6 smallint unsigned,
31        c7 smallint)");
32
33    mysqli_query($link, "INSERT INTO test_fetch VALUES ( -23, 35999, NULL, -500, -9999999, -0, 0)");
34
35    $result = mysqli_query($link, "SELECT * FROM test_fetch");
36    $test = mysqli_fetch_object($result, 'test_class', array(1, 2));
37    mysqli_free_result($result);
38
39    var_dump($test);
40
41    mysqli_close($link);
42
43    echo "Done\n";
44?>
45--CLEAN--
46<?php
47require_once("connect.inc");
48if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
49   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
50
51if (!mysqli_query($link, "DROP TABLE IF EXISTS test_fetch"))
52    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53
54mysqli_close($link);
55?>
56--EXPECTF--
57test_class::__construct(1,2)
58object(test_class)#%d (7) {
59  ["c1"]=>
60  string(1) "0"
61  ["c2"]=>
62  string(5) "35999"
63  ["c3"]=>
64  NULL
65  ["c4"]=>
66  string(4) "-500"
67  ["c5"]=>
68  string(6) "-32768"
69  ["c6"]=>
70  string(1) "0"
71  ["c7"]=>
72  string(1) "0"
73}
74Done
75