Annotation of embedaddon/php/ext/mysqli/tests/mysqli_prepare.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mysqli_prepare()
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifemb.inc');
! 7: require_once('skipifconnectfailure.inc');
! 8: ?>
! 9: --FILE--
! 10: <?php
! 11: require_once("connect.inc");
! 12:
! 13: $tmp = NULL;
! 14: $link = NULL;
! 15:
! 16: if (!is_null($tmp = @mysqli_prepare()))
! 17: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 18:
! 19: if (!is_null($tmp = @mysqli_prepare($link)))
! 20: printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 21:
! 22: require('table.inc');
! 23:
! 24: if (false !== ($tmp = @mysqli_prepare($link, false)))
! 25: printf("[003] Expecting boolean/false, got %s\n", gettype($tmp));
! 26:
! 27: if (!$res = mysqli_query($link, "SELECT id, label FROM test", MYSQLI_USE_RESULT))
! 28: printf("[004] [%d] %s, next test will fail\n", mysqli_errno($link), mysqli_error($link));
! 29:
! 30: if (false !== ($tmp = mysqli_prepare($link, 'SELECT id FROM test WHERE id > ?')))
! 31: printf("[005] Expecting boolean/false, got %s, [%d] %s\n", gettype($tmp), mysqli_errno($link), mysqli_error($link));
! 32:
! 33: mysqli_free_result($res);
! 34:
! 35: if (!is_object(($stmt = mysqli_prepare($link, 'SELECT id FROM test'))) || !mysqli_stmt_execute($stmt))
! 36: printf("[006][%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 37: mysqli_stmt_close($stmt);
! 38:
! 39:
! 40: if (!mysqli_query($link, "DROP TABLE IF EXISTS test2"))
! 41: printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 42:
! 43: if (!is_object(($stmt = mysqli_prepare($link, 'CREATE TABLE test2(id INT) ENGINE =' . $engine))) || !mysqli_stmt_execute($stmt))
! 44: printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 45: mysqli_stmt_close($stmt);
! 46:
! 47:
! 48: if (!is_object(($stmt = mysqli_prepare($link, 'INSERT INTO test2(id) VALUES(?)'))))
! 49: printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 50:
! 51: $id = 1;
! 52: if (!mysqli_stmt_bind_param($stmt, 'i', $id) || !mysqli_stmt_execute($stmt))
! 53: printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 54: mysqli_stmt_close($stmt);
! 55:
! 56: if (!is_object(($stmt = mysqli_prepare($link, 'REPLACE INTO test2(id) VALUES (?)'))))
! 57: printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 58:
! 59: $id = 2;
! 60: if (!mysqli_stmt_bind_param($stmt, 'i', $id) || !mysqli_stmt_execute($stmt))
! 61: printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 62: mysqli_stmt_close($stmt);
! 63:
! 64: if (!is_object(($stmt = mysqli_prepare($link, 'UPDATE test2 SET id = ? WHERE id = ?'))))
! 65: printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 66:
! 67: $id = 3;
! 68: $where = 2;
! 69: if (!mysqli_stmt_bind_param($stmt, 'ii', $id, $where) || !mysqli_stmt_execute($stmt))
! 70: printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 71: mysqli_stmt_close($stmt);
! 72:
! 73: if (!is_object(($stmt = mysqli_prepare($link, 'DELETE FROM test2 WHERE id = ?'))))
! 74: printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 75:
! 76: $where = 3;
! 77: if (!mysqli_stmt_bind_param($stmt, 'i', $where) || !mysqli_stmt_execute($stmt))
! 78: printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 79: mysqli_stmt_close($stmt);
! 80:
! 81: if (!is_object(($stmt = mysqli_prepare($link, 'SET @testvar = ?'))))
! 82: printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 83:
! 84: $testvar = 'testvar';
! 85: if (!mysqli_stmt_bind_param($stmt, 's', $testvar) || !mysqli_stmt_execute($stmt))
! 86: printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 87: mysqli_stmt_close($stmt);
! 88:
! 89: if (!is_object(($stmt = mysqli_prepare($link, "DO GET_LOCK('testlock', 1)"))))
! 90: printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 91: mysqli_stmt_close($stmt);
! 92:
! 93: if (!is_object(($stmt = mysqli_prepare($link, 'SELECT id, @testvar FROM test2'))))
! 94: printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 95:
! 96: $id = $testvar = null;
! 97: if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_bind_result($stmt, $id, $testvar))
! 98: printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 99: while (mysqli_stmt_fetch($stmt)) {
! 100: if (('testvar' !== $testvar) || (1 !== $id))
! 101: printf("[022] Expecting 'testvar'/1, got %s/%s. [%d] %s\n",
! 102: $testvar, $id, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
! 103: }
! 104:
! 105: var_dump(mysqli_stmt_prepare($stmt, 'SELECT 1; SELECT 2'));
! 106:
! 107: mysqli_stmt_close($stmt);
! 108:
! 109: if (!is_null($tmp = @mysqli_stmt_prepare($link, 'SELECT id FROM test', 'foo')))
! 110: printf("[023] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 111:
! 112: mysqli_close($link);
! 113:
! 114: if (!is_null($tmp = @mysqli_stmt_prepare($link, 'SELECT id FROM test')))
! 115: printf("[024] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 116:
! 117: print "done!";
! 118: ?>
! 119: --CLEAN--
! 120: <?php
! 121: require_once("connect.inc");
! 122: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
! 123: printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
! 124:
! 125: if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
! 126: printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 127:
! 128: if (!mysqli_query($link, "DROP TABLE IF EXISTS test2"))
! 129: printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
! 130:
! 131: mysqli_close($link);
! 132: ?>
! 133: --EXPECTF--
! 134: bool(false)
! 135: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>