PHP.mk документација

mysqli_stmt::$num_rows

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

mysqli-stmt.num-rows.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека mysqli-stmt.num-rows.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
mysqli_stmt::$num_rows

Референца за `mysqli-stmt.num-rows.php` со подобрена типографија и навигација.

mysqli-stmt.num-rows.php

mysqli_stmt::$num_rows

mysqli_stmt::num_rows

mysqli_stmt_num_rows

класата mysqli_driver

mysqli_stmt::$num_rows -- mysqli_stmt::num_rows -- mysqli_stmt_num_rowsReturns the number of rows fetched from the server

= NULL

Напиши целосна ознака на елемент

public mysqli_stmt::num_rows(): int|string

Процедурален стил

mysqli_stmt_num_rows(mysqli_stmt $statement): int|string

Враќа број на редови преземени од серверот mysqli_stmt_store_result() Враќа број на редови баферирани во изјавата. Оваа функција ќе работи само по

Оваа функција враќа 0 се повика за баферирање на целиот сет на резултати во рачката на изјавата.

Параметри

statement

објектот како свој прв аргумент. mysqli_stmt Само процедурален стил: А mysqli_stmt_init().

Вратени вредности

Еден int освен ако сите редови не се преземени од серверот. 0 во не-бафериран режим освен ако сите редови не се преземени од серверот.

Забелешка:

Ако бројот на редови е поголем од PHP_INT_MAX, бројот ќе биде вратен како string.

Примери

Пример #1 Обектно-ориентиран стил

<?php

mysqli_report
(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
$stmt = $mysqli->prepare($query);
$stmt->execute();

/* store the result in an internal buffer */
$stmt->store_result();

printf("Number of rows: %d.\n", $stmt->num_rows);

Пример #2 Процедурален стил

<?php

mysqli_report
(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);

/* store the result in an internal buffer */
mysqli_stmt_store_result($stmt);

printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt));

Горните примери ќе дадат излез:

Number of rows: 20.

Види Исто така

Белешки од корисници 1 белешка

Typer85 на gmail точка com
19 години пред
Please be advised, for people who sometimes miss to read this important Manual entry for this function:

If you do not use mysqli_stmt_store_result( ), and immediatley call this function after executing a prepared statement, this function will usually return 0 as it has no way to know how many rows are in the result set as the result set is not saved in memory yet.

mysqli_stmt_store_result( ) saves the result set in memory thus you can immedietly use this function after you both execute the statement AND save the result set.

If you do not save the result set but still want to use this function you have to actually loop through the result set one row at a time using mysqli_stmt_fetch( ) before using this function to determine the number of rows.

A thought though, if you want to determine the number of rows without storing the result set and after looping through it, why not just simply keep an internal counter in your loop every time a row is fetched and save the function call.

In short, this function is only really useful if you save the result set and want to determine the number of rows before looping through it, otherwise you can pretty much recreate its use like I suggested.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.