public function columnCount()
 {
     if ($this->_result) {
         return mysqli_stmt_field_count($this->_result);
     }
     return 0;
 }
}
$label = null;
if (mysqli_stmt_bind_param($stmt, "s", $label)) {
    printf("[014] expected error - got ok\n");
}
while (mysqli_stmt_fetch($stmt)) {
    if (1 !== ($tmp = mysqli_stmt_field_count($stmt))) {
        printf("[015] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
    }
}
if (!mysqli_stmt_prepare($stmt, 'INSERT INTO test(id) VALUES (100)')) {
    printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (0 !== ($tmp = mysqli_stmt_field_count($stmt))) {
    printf("[017] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
}
if (!mysqli_stmt_prepare($stmt, "UPDATE test SET label = 'z' WHERE id = 1") || !mysqli_stmt_execute($stmt)) {
    printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (0 !== ($tmp = mysqli_stmt_field_count($stmt))) {
    printf("[019] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_stmt_close($stmt);
if (mysqli_stmt_prepare($stmt, 'SELECT id FROM test')) {
    printf("[020] Prepare should fail, statement has been closed\n");
}
if (!is_null($tmp = mysqli_stmt_field_count($stmt))) {
    printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
print "done!";
}
printf("\nMagic, magic properties:\n");
assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
if (!$stmt->prepare("INSERT INTO test_mysqli_class_mysqli_stmt_interface_table_1(id, label) VALUES (100, 'z')") || !$stmt->execute()) {
    printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
}
assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
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);
 if ($fields_res_meta != $fields) {
     printf("[016] Prepared Statement metadata differs from normal metadata, dumping\n");
     var_dump($fields_res_meta);
     var_dump($fields);
 }
 if (function_exists('mysqli_stmt_get_result') && $stmt->prepare('EXPLAIN SELECT t1.*, t2.* FROM test AS t1, test AS t2') && $stmt->execute()) {
     if (!($res_stmt = mysqli_stmt_get_result($stmt))) {
         printf("[017] Cannot fetch result from PS [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
     }
     if (($tmp = mysqli_num_rows($res_stmt)) !== $num_rows) {
         printf("[018] Expecting int/%d got %s/%s\n", $num_rows, gettype($tmp), $tmp);
     }
     if (mysqli_stmt_num_rows($stmt) !== 0) {
         printf("[019] Expecting int/0 got %s/%s\n", gettype($tmp), $tmp);
     }
     if (($tmp = mysqli_stmt_field_count($stmt)) !== $num_fields) {
         printf("[020] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
     }
     if (($tmp = $res_stmt->field_count) !== $num_fields) {
         printf("[021] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
     }
     $fields_stmt = mysqli_fetch_fields($res_stmt);
     if (($tmp = count($fields_stmt)) !== $num_fields) {
         printf("[022] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
     }
     reset($fields);
     foreach ($fields_stmt as $fields_stmt_val) {
         list(, $fields_val) = each($fields);
         unset($fields_stmt_val->max_length);
         unset($fields_val->max_length);
         if ($fields_stmt_val != $fields_val) {
 public static function columnCount($rs)
 {
     if ($rs) {
         if (get_class($rs) == "mysqli_result") {
             return mysqli_num_fields($rs);
         } else {
             return mysqli_stmt_field_count($rs);
         }
     } else {
         return 0;
     }
 }
Beispiel #6
0
 /**
  * Number of fields in the result set
  *
  * @access	public
  * @return	integer
  */
 function num_fields()
 {
     return @mysqli_stmt_field_count($this->prepare_statement);
 }