MySQLi Function in PHP: Part 6

Introduction

In this article I describe the PHP MySQLi  functions mysqli_field_seek, mysqli_field_tell, mysqli_free_result, mysqli_get_charset and mysqli-get_client_info. To learn some other MySQLi functions, go to:

  1. MySQLi Function in PHP: Part 1
  2. MySQLi Function in PHP: Part 2
  3. MySQLi Function in PHP: Part 3
  4. MySQLi Function in PHP: Part 4
  5. MySQLi Function in PHP: Part 5

PHP mysqli_field_seek() Function

The PHP MySQLi "mysqli_field_seek" function sets the field cursor to a specified field offset and this function returns true on success or false on failure.

Syntax

mysqli_field_seek(result,fieldnr)

Parameter in mysqli_field_seek function

The parameters of the function are: 

Parameter Description
result It specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_user_result().
fieldnr It specifies the field number and this number must be an integer between 0 and number of field -1.

Example

An example of the function is:


<?
php
$
con=mysqli_connect("localhost","root","","mysql");
if (mysqli_connect_errno($con))
  {
  echo "
Failed to connect to MySQL: " . mysqli_connect_error();
  }
if($result=mysqli_query($con,"
SELECT * FROM emp"))
{
mysqli_field_seek($result,0);
$info=mysqli_fetch_field($result);
printf("<
b>Emp Name: </b>%s",$info->name);
echo "
<br>";
printf("
<b>Table Name: </b>%s",$info->table);
echo "
<br>";
printf("
<b>max. Len:</b> %d\n",$info->max_length);
}
mysqli_close($con);

?>


Output
 
mysqli-filed-seek-function-in-php.jpg

PHP mysqli_field_tell() Function

The PHP MySQLi "mysqli_field_tell" function returns the position of the field cursor or in other words this function returns the current offset of the field cursor on success.

Syntax

mysqli_field_tell(result)

Parameter in mysqli_field_seek function

The parameter of the function is: 

Parameter Description
result It specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_user_result().

Example

An example of the function is:


<?
php
$
con=mysqli_connect("localhost","root","","mysql");
if (mysqli_connect_errno($con))
  {
  echo "
Failed to connect to MySQL: " . mysqli_connect_error();
  }
if($result=mysqli_query($con,"
SELECT * FROM emp"))
{
mysqli_field_seek($result,0);
while($info=mysqli_fetch_field($result))
{
$currentField=mysqli_field_tell($result);
echo "<
h1>Column". $currentField."</h1>";
printf("
<b>Column Name: </b>%s",$info->name);
printf("
<b> Table Name: </b>%s",$info->table);
printf("
<b> max. Len:</b> %d\n",$info->max_length);
echo "
<br>";
}
}
mysqli_close($con);

?>


Output

mysqli-field-tell-function-in-php.jpg

PHP mysqli_free_result() Function

The PHP MySQLi "mysqli_free_result" function frees memory associated with a result and this function returns true on success or false on failure.

Syntax

mysqli_free_result(result)

Parameter in mysqli_free_result function

The parameter of the function is: 

Parameter Description
result It specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_user_result().

Example

An example of the function is:


<?
php
$
con=mysqli_connect("localhost","root","","mysql");
if (mysqli_connect_errno($con))
  {
  echo "
Failed to connect to MySQL: " . mysqli_connect_error();
  }
echo "<
table border='1'>
<
tr>
<
th>EmpId</th>
<
th>EmpName</th>
<
th>EmpSalary</th>
</
tr>";
if($qry=mysqli_query($con,"SELECT * FROM emp"))
{
while($res=mysqli_fetch_row($qry))
{
echo "
<tr>";
echo "
<td>" . $res[0] . "</td>";
echo "
<td>" . $res[1] . "</td>";
echo "
<td>" . $res[2] . "</td>";
echo "
</tr>";
}
mysqli_free_result($qry);
}
echo "
</table>";
mysqli_close($con);

?> 

Output

mysqli-free-result-function-in-php.jpg

PHP mysqli_get_charset() Function

The PHP MySQLi "mysqli_get_charset" function sets the default client character set and this function returns true on success or  false on failure.

Syntax

mysqli_get_charset(connection)

Parameter in mysqli_get_charset function

The parameter of the function is:

Parameter Description
connection It specifies the MySQL connection  to use.

Example

An example of the function is:


<?
php
$
con=mysqli_connect("localhost","root","","mysql");
if (mysqli_connect_errno($con))
  {
  echo "
Failed to connect to MySQL: " . mysqli_connect_error();
  }
  echo "<
pre>";
var_dump(mysqli_get_charset($con));
mysqli_close($con);

?>


Output

mysqli-get-charset-function-in-php.jpg

PHP mysqli_get_client_info() Function

The PHP MySQLi "mysqli_get_client_info" function gets the MySQL client info and this function returns a string that represents the MySQL client library version.


Example

An example of the function is:

<?php

$con=mysqli_connect("localhost","root","","mysql");

if (mysqli_connect_errno($con))

  {

  echo "Failed to connect to MySQL: " . mysqli_connect_error();

  } 

echo mysqli_get_client_info($con);

mysqli_close($con);

?>

Output

mysqli-get-client-info-function-in-php.jpg


Similar Articles