English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel PHP de base

Tutoriel PHP avancé

PHP & MySQL

Manuel de référence PHP

Utilisation et exemple de la fonction mysqli_field_tell() PHP

PHP MySQLi Référence Manuel

La fonction mysqli_field_tell() retourne la position du pointeur de champ.

Définition et utilisation

Un objet de résultat PHP (classe mysqli_result) représente les résultats de MySQL renvoyés par une requête SELECT ou DESCRIBE ou EXPLAIN. Le curseur des champs de l'objet de résultat/Le pointeur pointe sur le champ (valeur de colonne) en question.

mysqli_field_tell()La fonction accepte un objet de résultat en paramètre, recherche et retourne la position actuelle du pointeur de champ dans l'objet donné.

Syntaxe

mysqli_field_tell($result);

Parameter

Serial NumberParameters and Description
1

result(必需)

This is the identifier representing the result object.

Return Value

The PHP mysqli_field_tell() function returns an integer value that specifies the position of the field pointer in the given result object.

PHP version

This function was originally in PHP version5introduces, and can be used in all higher versions.

Exemple en ligne

The following example demonstratesmysqli_field_tell()Usage of the function (procedural style), obtain all field information, and then output the field name, table name, and data type through mysqli_field_tell():

<?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("Créer une 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', 'Srilanka')");
   print("Inserting records.....\n");
   //Retrieve the content of the table
   $res = mysqli_query($con, "SELECT * FROM myplayers");
   //Get Field
   while($info = mysqli_fetch_field($res)){
      //Current Field
      $currentfield = mysqli_field_tell($res);
      print("Current Field: ").$currentfield."\n");
      print("Name: ").$info->name."\n");
      print("Table: ").$info->table."\n");
      print("Type: ").$info->type.\n\
   }
   //Terminer l'instruction
   mysqli_free_result($res);
   //Fermer la connexion
   mysqli_close($con);
?>

Résultat de la sortie

Créer une table.....
Insérer un enregistrement.....
Champ courant : 1
Nom : ID
Table : myplayers
Type : 3
Champ courant : 2
Nom : Prénom
Table : myplayers
Type : 253
Champ courant : 3
Nom : Nom_de_famille
Table : myplayers
Type : 253
Champ courant : 4
Nom : Lieu_de_naissance
Table : myplayers
Type : 253
Champ courant : 5
Nom : Pays
Table : myplayers
Type : 253

Exemple en ligne

Dans le style orienté objet, la syntaxe de cette fonction est$result-> current_field;。Voici un exemple de cette fonction pour obtenir le champ courant et renvoyer le nom du champ dans un style orienté objet ;

<?php
   //Établir la connexion
   $con = new mysqli("localhost", "root", "password", "mydb");
   $con -> query("CREATE TABLE Test(Name VARCHAR(255), ÂGE INT)");
   $con -> query("insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27);
   print("Créer une table.....\n");
   $stmt = $con -> prepare("SELECT * FROM Test WHERE Name in(?, ?)
   $stmt -> bind_param("ss", $name1, $name2);
   $name1 = 'Raju';
   $name2 = 'Rahman';
   //Exécuter l'instruction
   $stmt->execute();
   //Résultat de la recherche
   $result = $stmt->get_result();
   //Champ courant
   $info = $result->fetch_field();
   $field = $result->current_field;
   print("Champ courant : ").$field.\n\
   print("Nom de champ : ").$info->name);
   //Terminer l'instruction
   $stmt->fermer();
   //Fermer la connexion
   $con->fermer();
?>

Résultat de la sortie

Créer une table.....
Champ courant : 1
Nom de champ : Nom

PHP MySQLi Référence Manuel