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