예제 #1
0
function func_test_mysqli_stmt_param_count_table_1_mysqli_stmt_param_count($stmt, $query, $expected, $offset)
{
    if (!mysqli_stmt_prepare($stmt, $query)) {
        printf("[%03d] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_error($stmt));
        return false;
    }
    if ($expected !== ($tmp = mysqli_stmt_param_count($stmt))) {
        printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 3, gettype($expected), $expected, gettype($tmp), $tmp);
    }
    return true;
}
예제 #2
0
파일: db.php 프로젝트: rsnel/logdb
function db_vce_stmt($query, $args) {
	$refs = array();

	if (!($refs[0] = mysqli_prepare($GLOBALS['db'], $query))) fatal_mysqli('msqli_prepare');
	$refs[1] = '';
	
	if (mysqli_stmt_param_count($refs[0]) != count($args))
		fatal('prepared statement expects '.myqsqli_stmt_param_count($refs[0]).' parameter(s) but gets '.count($args).' parameter(s): '.$query);

	// bind parameters if there are any
	if (count($args)) {
		foreach ($args as &$arg) {
			$refs[] = &$arg;
			$type = gettype($arg);
			switch ($type) {
				case 'integer':
					$refs[1] .= 'i';
					break;
				case 'string':
					$refs[1] .= 's';
					break;
				case 'NULL':
					$refs[1] .= 'i';
					break;
				default:
					fatal('unsupported type ('.$type.') for MySQL query (only integer, NULL and string supported)');
			}
		}

		if (!call_user_func_array('mysqli_stmt_bind_param', $refs)) fatal_mysqli('mysqli_bind_param');
	}

	if (!mysqli_stmt_execute($refs[0])) fatal_mysqli('mysqli_stmt_execute');

	return $refs[0];
}
printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
assert(mysqli_stmt_errno($stmt) === $stmt->errno);
printf("stmt->errno = '%s'\n", $stmt->errno);
assert(mysqli_stmt_error($stmt) === $stmt->error);
printf("stmt->error = '%s'\n", $stmt->error);
assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
var_dump("stmt->error = ", $stmt->error_list);
assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
printf("stmt->field_count = '%s'\n", $stmt->field_count);
assert($stmt->id > 0);
printf("stmt->id = '%s'\n", $stmt->id);
assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
printf("stmt->param_count = '%s'\n", $stmt->param_count);
assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
printf("\nAccess to undefined properties:\n");
printf("stmt->unknown = '%s'\n", @$stmt->unknown);
@($stmt->unknown = 13);
printf("stmt->unknown = '%s'\n", @$stmt->unknown);
printf("\nPrepare using the constructor:\n");
$stmt = new mysqli_stmt($link, 'SELECT id FROM test_mysqli_class_mysqli_stmt_interface_table_1 ORDER BY id');
if (!$stmt->execute()) {
    printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
}
$stmt->close();
$obj = new stdClass();
if (!is_object($stmt = new mysqli_stmt($link, $obj))) {