English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A função mysqli_stmt_field_count() retorna o número de campos na sentença fornecida.
mysqli_stmt_field_count()A função aceita um objeto de sentença como parâmetro e retorna o número de campos no resultado da sentença fornecida.
mysqli_stmt_field_count($stmt)
Número | Parâmetros e descrição |
---|---|
1 | stmt (obrigatório) Este é o objeto que representa a consulta SQL executada. |
A função mysqli_stmt_field_count() do PHP retorna um valor inteiro que indica o número de linhas no conjunto de resultados da consulta.
Esta função foi introduzida inicialmente na versão do PHP5introduzido e pode ser usado em todas as versões mais recentes.
A seguir, um exemplo demonstra:mysqli_stmt_field_count()A utilização da função (estilo procedimental), retorna o número de campos:
<?php $con = mysqli_connect("localhost", "root", "password", "mydb"); mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))"); print("Creating table.....\n"); mysqli_query($con, "INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')"); mysqli_query($con, "INSERT INTO myplayers values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')"); mysqli_query($con, "INSERT INTO myplayers values(3, 'Kumara', 'Sangakkara', 'Matale', 'Sri Lanka'); print("Inserting records.....\n"); //Retrieve the content of the table $stmt = mysqli_prepare($con, "SELECT * FROM myplayers"); //Execute statement mysqli_stmt_execute($stmt); //Number of fields $count = mysqli_stmt_field_count($stmt); print("Number of fields : ".$count); //End statement mysqli_stmt_close($stmt); //Close connection mysqli_close($con); ?>
Output results
Creating table..... Inserting records..... Number of fields : 5
In the object-oriented style, the syntax of this function is$stmt->field_count;.Here is an example of this function in an object-oriented style;
<?php //Establish connection $con = new mysqli("localhost", "root", "password", "mydb"); $con ->query("CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))"); print("Creating table.....\n"); $con ->query("INSERT INTO myplayers values(")1, 'Sikhar', 'Dhawan', 'Delhi', 'India')"); $con ->query("INSERT INTO myplayers values(")2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')"); print("Inserting records.....\n"); //Retrieve data $stmt = $con ->prepare("SELECT First_Name, Last_Name, Country FROM myplayers"); //Execute statement $stmt->execute(); //Number of fields $count = $stmt->field_count; print("Number of fields: ".$count); //End statement $stmt->close(); //Close connection $con->close(); ?>
Output results
Creating table..... Inserting records..... Number of fields: 3