xref: /PHP-8.0/ext/mysqli/tests/003.phpt (revision e3e67b72)
1--TEST--
2mysqli connect
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
13
14    mysqli_query($link, "SET sql_mode=''");
15
16    if (!mysqli_query($link,"DROP TABLE IF EXISTS test_bind_result"))
17        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
18
19    $rc = @mysqli_query($link,"CREATE TABLE test_bind_result(
20        c1 date,
21        c2 time,
22        c3 timestamp(14),
23        c4 year,
24        c5 datetime,
25        c6 timestamp(4),
26        c7 timestamp(6)) ENGINE=" . $engine);
27
28    /*
29    Seems that not all MySQL 6.0 installations use defaults that ignore the display widths.
30    From the manual:
31    From MySQL 4.1.0 on, TIMESTAMP display format differs from that of earlier MySQL releases:
32    [...]
33    Display widths (used as described in the preceding section) are no longer supported.
34    In other words, for declarations such as TIMESTAMP(2), TIMESTAMP(4), and so on,
35    the display width is ignored.
36    [...]
37    */
38    if (!$rc)
39        $rc = @mysqli_query($link,"CREATE TABLE test_bind_result(
40            c1 date,
41            c2 time,
42            c3 timestamp,
43            c4 year,
44            c5 datetime,
45            c6 timestamp,
46            c7 timestamp) ENGINE=" . $engine);
47
48    if (!$rc)
49        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
50
51    $rc = mysqli_query($link, "INSERT INTO test_bind_result VALUES(
52        '2002-01-02',
53        '12:49:00',
54        '2002-01-02 17:46:59',
55        2010,
56        '2010-07-10',
57        '2020','1999-12-29')");
58    if (!$rc)
59        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
60
61    $stmt = mysqli_prepare($link, "SELECT c1, c2, c3, c4, c5, c6, c7 FROM test_bind_result");
62    mysqli_stmt_bind_result($stmt, $c1, $c2, $c3, $c4, $c5, $c6, $c7);
63    mysqli_stmt_execute($stmt);
64    mysqli_stmt_fetch($stmt);
65
66    $test = array($c1,$c2,$c3,$c4,$c5,$c6,$c7);
67
68    var_dump($test);
69
70    mysqli_stmt_close($stmt);
71    mysqli_query($link, "DROP TABLE IF EXISTS test_bind_result");
72    mysqli_close($link);
73    print "done!";
74?>
75--CLEAN--
76<?php
77require_once("connect.inc");
78if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
79   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
80
81if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_result"))
82    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
83
84mysqli_close($link);
85?>
86--EXPECT--
87array(7) {
88  [0]=>
89  string(10) "2002-01-02"
90  [1]=>
91  string(8) "12:49:00"
92  [2]=>
93  string(19) "2002-01-02 17:46:59"
94  [3]=>
95  int(2010)
96  [4]=>
97  string(19) "2010-07-10 00:00:00"
98  [5]=>
99  string(19) "0000-00-00 00:00:00"
100  [6]=>
101  string(19) "1999-12-29 00:00:00"
102}
103done!
104