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