xref: /php-src/ext/mysqli/tests/036.phpt (revision a21edc52)
1--TEST--
2function test: mysqli_insert_id()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7    if (PHP_INT_SIZE == 8) {
8        echo 'skip test valid only for 32bit systems';
9        exit;
10    }
11    require_once 'skipifconnectfailure.inc';
12?>
13--FILE--
14<?php
15    require_once 'connect.inc';
16
17    /*** test mysqli_connect 127.0.0.1 ***/
18    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
19
20    mysqli_select_db($link, $db);
21
22    mysqli_query($link, "DROP TABLE IF EXISTS t036");
23    mysqli_query($link, "CREATE TABLE t036 (a bigint not null auto_increment primary key, b varchar(10)) ENGINE = " . $engine);
24
25    mysqli_query($link, "INSERT INTO t036 (b) VALUES ('foo1')");
26    $test[] = mysqli_insert_id($link);
27
28    /* we have to insert more values, cause lexer sets auto_increment to max_int
29       see mysql bug #54. So we don't check for the value, only for type (which must
30       be type string)
31    */
32
33    mysqli_query($link, "ALTER TABLE t036 AUTO_INCREMENT=9999999999999998");
34    mysqli_query($link, "INSERT INTO t036 (b) VALUES ('foo2')");
35    mysqli_query($link, "INSERT INTO t036 (b) VALUES ('foo3')");
36    mysqli_query($link, "INSERT INTO t036 (b) VALUES ('foo4')");
37    $x = mysqli_insert_id($link);
38    $test[] = is_string($x);
39
40    var_dump($test);
41
42    mysqli_query($link, "DROP TABLE IF EXISTS t036");
43    mysqli_close($link);
44    print "done!";
45?>
46--CLEAN--
47<?php
48require_once 'connect.inc';
49if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
50   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
51
52if (!mysqli_query($link, "DROP TABLE IF EXISTS t036"))
53    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54
55mysqli_close($link);
56?>
57--EXPECT--
58array(2) {
59  [0]=>
60  int(1)
61  [1]=>
62  bool(true)
63}
64done!
65