1--TEST--
2mysqli insert (bind_param + bind_result) datetime types
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";
8mysqli_check_skip_test();
9?>
10--FILE--
11<?php
12require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";
13
14$link = default_mysqli_connect();
15
16// To get consistent result without depending on the DB version/setup
17mysqli_query($link, "SET sql_mode=''");
18
19/* 14 Too big precision for timestamp */
20mysqli_query(
21    $link,
22    "CREATE TABLE insert_bind_datetime(
23        c1 date,
24        c2 time,
25        c3 timestamp,
26        c4 year,
27        c5 datetime,
28        c6 timestamp,
29        c7 timestamp
30    )"
31);
32
33$stmt = mysqli_prepare($link, "INSERT INTO insert_bind_datetime VALUES (?,?,?,?,?,?,?)");
34mysqli_stmt_bind_param($stmt, "sssssss", $d1, $d2, $d3, $d4, $d5, $d6, $d7);
35
36$d1 = "2002-01-02";
37$d2 = "12:49:00";
38$d3 = "2002-01-02 17:46:59";
39$d4 = "2010";
40$d5 = "2010-07-10";
41$d6 = "2020";
42$d7 = "1999-12-29";
43
44mysqli_stmt_execute($stmt);
45mysqli_stmt_close($stmt);
46
47$stmt = mysqli_prepare($link, "SELECT c1, c2, c3, c4, c5, c6, c7 FROM insert_bind_datetime");
48
49mysqli_stmt_bind_result($stmt,$c1, $c2, $c3, $c4, $c5, $c6, $c7);
50
51mysqli_stmt_execute($stmt);
52mysqli_stmt_fetch($stmt);
53
54$test = array($c1,$c2,$c3,$c4,$c5,$c6,$c7);
55
56var_dump($test);
57
58mysqli_stmt_close($stmt);
59mysqli_close($link);
60
61print "done!";
62?>
63--CLEAN--
64<?php
65require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";
66tear_down_table_on_default_connection('insert_bind_datetime');
67?>
68--EXPECTF--
69array(7) {
70  [0]=>
71  %s(10) "2002-01-02"
72  [1]=>
73  %s(8) "12:49:00"
74  [2]=>
75  %s(19) "2002-01-02 17:46:59"
76  [3]=>
77  string(4) "2010"
78  [4]=>
79  %s(19) "2010-07-10 00:00:00"
80  [5]=>
81  %s(19) "0000-00-00 00:00:00"
82  [6]=>
83  %s(19) "1999-12-29 00:00:00"
84}
85done!
86