xref: /php-src/ext/mysqli/tests/bug66124.phpt (revision 7e5171d1)
1--TEST--
2Bug #66124 (mysqli under mysqlnd loses precision when bind_param with 'i')
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11$table_drop = "DROP TABLE IF EXISTS `test`";
12$table_create = "CREATE TABLE `test` (
13  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
14  PRIMARY KEY (`id`)
15) ENGINE=InnoDB DEFAULT CHARSET=utf8";
16
17$table_insert = "INSERT INTO `test` SET `id`=?";
18$table_select = "SELECT * FROM `test`";
19$id = '1311200011005001566';
20
21
22require_once 'connect.inc';
23
24if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
25    printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
26        $host, $user, $db, $port, $socket);
27    exit(1);
28}
29
30$link->query($table_drop);
31$link->query($table_create);
32
33$stmt = $link->prepare($table_insert);
34if (!$stmt) {
35    printf("Can't prepare\n");
36    exit(1);
37}
38
39echo "Using 'i':\n";
40$stmt->bind_param('i', $id);
41
42if ($stmt->execute()){
43    echo "insert id:{$id}=>{$stmt->insert_id}\n";
44} else {
45    printf("Can't execute\n");
46    exit(1);
47}
48
49
50$result = $link->query($table_select);
51
52if ($result){
53    while ($row = $result->fetch_assoc()) {
54        echo "fetch  id:{$row['id']}\n";
55    }
56} else {
57    printf("Can't select\n");
58    exit(1);
59}
60
61$stmt->close();
62
63$link->query($table_drop);
64$link->query($table_create);
65
66
67$stmt = $link->prepare($table_insert);
68$stmt->bind_param('s', $id);
69
70echo "Using 's':\n";
71
72if ($stmt->execute()){
73    echo "insert id:{$id}\n";
74} else{
75    printf("Can't execute\n");
76    exit(1);
77}
78
79$result = $link->query($table_select);
80
81if ($result){
82    while ($row = $result->fetch_assoc()) {
83        echo "fetch  id:{$row['id']}\n";
84    }
85} else {
86    printf("Can't select\n");
87    exit(1);
88}
89
90$link->close();
91?>
92done
93--CLEAN--
94<?php
95require_once 'clean_table.inc';
96?>
97--EXPECT--
98Using 'i':
99insert id:1311200011005001566=>1311200011005001566
100fetch  id:1311200011005001566
101Using 's':
102insert id:1311200011005001566
103fetch  id:1311200011005001566
104done
105