xref: /php-src/ext/mysqli/tests/bug66124.phpt (revision a21edc52)
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$table_delete = "DELETE FROM `test`";
20$id = '1311200011005001566';
21
22
23require_once 'connect.inc';
24
25if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
26    printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
27        $host, $user, $db, $port, $socket);
28    exit(1);
29}
30
31$link->query($table_drop);
32$link->query($table_create);
33
34$stmt = $link->prepare($table_insert);
35if (!$stmt) {
36    printf("Can't prepare\n");
37    exit(1);
38}
39
40echo "Using 'i':\n";
41$stmt->bind_param('i', $id);
42
43if ($stmt->execute()){
44    echo "insert id:{$id}=>{$stmt->insert_id}\n";
45} else {
46    printf("Can't execute\n");
47    exit(1);
48}
49
50
51$result = $link->query($table_select);
52
53if ($result){
54    while ($row = $result->fetch_assoc()) {
55        echo "fetch  id:{$row['id']}\n";
56    }
57} else {
58    printf("Can't select\n");
59    exit(1);
60}
61
62$stmt->close();
63
64$link->query($table_drop);
65$link->query($table_create);
66
67
68$stmt = $link->prepare($table_insert);
69$stmt->bind_param('s', $id);
70
71echo "Using 's':\n";
72
73if ($stmt->execute()){
74    echo "insert id:{$id}\n";
75} else{
76    printf("Can't execute\n");
77    exit(1);
78}
79
80$result = $link->query($table_select);
81
82if ($result){
83    while ($row = $result->fetch_assoc()) {
84        echo "fetch  id:{$row['id']}\n";
85    }
86} else {
87    printf("Can't select\n");
88    exit(1);
89}
90
91$link->close();
92?>
93done
94--CLEAN--
95<?php
96require_once 'clean_table.inc';
97?>
98--EXPECT--
99Using 'i':
100insert id:1311200011005001566=>1311200011005001566
101fetch  id:1311200011005001566
102Using 's':
103insert id:1311200011005001566
104fetch  id:1311200011005001566
105done
106