Annotation of embedaddon/php/ext/mysql/tests/mysql_insert_id.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: mysql_insert_id()
                      3: --SKIPIF--
                      4: <?php
                      5: require_once('skipif.inc');
                      6: require_once('skipifconnectfailure.inc');
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: include "connect.inc";
                     11: include 'setupdefault.inc';
                     12: 
                     13: $tmp    = NULL;
                     14: $link   = NULL;
                     15: 
                     16: if (0 !== ($tmp = @mysql_insert_id()))
                     17:        printf("[001] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
                     18: 
                     19: if (NULL !== ($tmp = @mysql_insert_id($link)))
                     20:        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     21: 
                     22: if (!is_null($tmp = @mysql_insert_id($link, 'too many args')))
                     23:        printf("[002a] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     24: 
                     25: require('table.inc');
                     26: 
                     27: if (0 !== ($tmp = mysql_insert_id($link)))
                     28:        printf("[003] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
                     29: 
                     30: if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 1", $link)) {
                     31:        printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     32: }
                     33: if (0 !== ($tmp = mysql_insert_id($link)))
                     34:        printf("[005] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
                     35: mysql_free_result($res);
                     36: 
                     37: // no auto_increment column
                     38: if (!$res = mysql_query("INSERT INTO test(id, label) VALUES (100, 'a')", $link)) {
                     39:        printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     40: }
                     41: if (0 !== ($tmp = mysql_insert_id($link)))
                     42:        printf("[007] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
                     43: 
                     44: if (!$res = mysql_query("ALTER TABLE test MODIFY id INT NOT NULL AUTO_INCREMENT", $link)) {
                     45:        printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     46: }
                     47: if (!$res = mysql_query("INSERT INTO test(label) VALUES ('a')", $link)) {
                     48:        printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     49: }
                     50: if (0 === ($tmp = mysql_insert_id($link)))
                     51:        printf("[010] Expecting int/not zero, got %s/%s\n", gettype($tmp), $tmp);
                     52: 
                     53: if ($tmp !== ($tmp2 = mysql_insert_id()))
                     54:        printf("[011] Expecting %s/%s, got %s/%s\n",
                     55:                gettype($tmp), $tmp,
                     56:                gettype($tmp2), $tmp2);
                     57: 
                     58: mysql_close($link);
                     59: 
                     60: var_dump(mysql_insert_id($link));
                     61: 
                     62: print "done!";
                     63: ?>
                     64: --CLEAN--
                     65: <?php
                     66: require_once("clean_table.inc");
                     67: ?>
                     68: --EXPECTF--
                     69: Warning: mysql_insert_id(): %d is not a valid MySQL-Link resource in %s on line %d
                     70: bool(false)
                     71: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>