<?Php require "config.php";// Database connection file. $query="select * from student where id=7 "; if ($result_set = mysqli_query($connection,$query)) { $row = mysqli_fetch_row($result_set); echo $row[1]."<br>"; foreach (mysqli_fetch_lengths($result_set) as $i => $val) { echo " Field No ". $i ." value: ".$val . ","; } } ?>
Krish Star Field No 0 value: 1, Field No 1 value: 10, Field No 2 value: 4, Field No 3 value: 2, Field No 4 value: 6,
$result_set->lengths;
mysqli_fetch_lengths
The input parameter $result_set is the output of result set identifier of mysqli_query(), mysqli_store_result() or mysqli_use_result().
MySQLI database connection file
Procedural style<?Php require "config.php";// Database connection file. $q="SELECT * FROM student where id=4"; if ($result = $connection->query($q)){ $row = $result->fetch_row(); echo $row[1]."<br>"; foreach ($result->lengths as $i => $val) { echo " Field No ". $i ." value: ".$val . ","; } $result->close(); } ?>
<?Php
require "config.php";// Database connection,returns the object $connection
$query='SELECT * FROM student';
if ($result = $connection->query($query)) {
while ($row = $result->fetch_assoc()) {
echo "<br><br><b>".$row['id'],$row['name'],$row['class'].$row['mark']."</b>";
foreach ($result->lengths as $i => $val) {
printf("<br>Field %2d has Length %2d\n", $i+1, $val);
}
}
}
?>
<?Php
require "config.php";// Database connection,returns the object $connection
$query='SELECT * FROM student';
if ($result = mysqli_query($connection, $query)) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<br><br><b>".$row['id'],$row['name'],$row['class'].$row['mark']."</b>";
/* display column lengths */
foreach (mysqli_fetch_lengths($result) as $i => $val) {
printf("<br>Field %2d has Length %2d\n", $i+1, $val);
}
}
}
?>
output ( sample rows only )
1John DeoFour75
Field 1 has Length 1
Field 2 has Length 8
Field 3 has Length 4
Field 4 has Length 2
Field 5 has Length 6
2Max RuinThree85
Field 1 has Length 1
Field 2 has Length 8
Field 3 has Length 5
Field 4 has Length 2
Field 5 has Length 4
3ArnoldThree55
Field 1 has Length 1
Field 2 has Length 6
Field 3 has Length 5
Field 4 has Length 2
Field 5 has Length 4
------
------
MYSQLI Functionsmysqli_num_rows() Number of rows in result set
SELECT query
UPDATE query
mysqli_fetch_field_direct(): Field meta data