xref: /PHP-8.1/ext/mysqli/tests/020.phpt (revision b5a14e6c)
1--TEST--
2mysqli bind_param/bind_result date
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_result");
20
21    $rc = @mysqli_query($link,"CREATE TABLE test_bind_result(
22        c1 date,
23        c2 time,
24        c3 timestamp(14),
25        c4 year,
26        c5 datetime,
27        c6 timestamp(4),
28        c7 timestamp(6))");
29
30    if (!$rc)
31        $rc = mysqli_query($link,"CREATE TABLE test_bind_result(
32        c1 date,
33        c2 time,
34        c3 timestamp,
35        c4 year,
36        c5 datetime,
37        c6 timestamp,
38        c7 timestamp)");
39
40    $stmt = mysqli_prepare($link, "INSERT INTO test_bind_result VALUES (?,?,?,?,?,?,?)");
41    mysqli_stmt_bind_param($stmt, "sssssss", $d1, $d2, $d3, $d4, $d5, $d6, $d7);
42
43    $d1 = "2002-01-02";
44    $d2 = "12:49:00";
45    $d3 = "2002-01-02 17:46:59";
46    $d4 = "2010";
47    $d5 = "2010-07-10";
48    $d6 = "2020";
49    $d7 = "1999-12-29";
50
51    mysqli_stmt_execute($stmt);
52    mysqli_stmt_close($stmt);
53
54    $stmt = mysqli_prepare($link, "SELECT c1, c2, c3, c4, c5, c6, c7 FROM test_bind_result");
55
56    mysqli_stmt_bind_result($stmt,$c1, $c2, $c3, $c4, $c5, $c6, $c7);
57
58    mysqli_stmt_execute($stmt);
59    mysqli_stmt_fetch($stmt);
60
61    $test = array($c1,$c2,$c3,$c4,$c5,$c6,$c7);
62
63    var_dump($test);
64
65    mysqli_stmt_close($stmt);
66    mysqli_query($link, "DROP TABLE IF EXISTS test_bind_result");
67    mysqli_close($link);
68
69    print "done!";
70?>
71--CLEAN--
72<?php
73require_once("connect.inc");
74if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
75   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
76
77if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_result"))
78    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
79
80mysqli_close($link);
81?>
82--EXPECTF--
83array(7) {
84  [0]=>
85  %s(10) "2002-01-02"
86  [1]=>
87  %s(8) "12:49:00"
88  [2]=>
89  %s(19) "2002-01-02 17:46:59"
90  [3]=>
91  string(4) "2010"
92  [4]=>
93  %s(19) "2010-07-10 00:00:00"
94  [5]=>
95  %s(19) "0000-00-00 00:00:00"
96  [6]=>
97  %s(19) "1999-12-29 00:00:00"
98}
99done!
100