We now have a youtube channel. Subscribe!

PHP | mysqli_stmt_data_seek() Function

PHP  mysqli_stmt_data_seek() Function

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP mysqli_stmt_data_seek() Function.

The built-in PHP mysqli_stmt_data_seek() function accepts a statement object and an integer value as parameters and seeks to the specified row in the result set of the given statement (if any).


Following below is the syntax to use this function -


Parameter Details

Sr.NoParameter & Description


This is an object representing a prepared statement.



This is an integer value representing the desired row (must be between 0 and the total number of rows in the result set).

Return Value

This built-in PHP function does not return any value.

PHP Version

This PHP function was first introduced in PHP version 5 and works in all the later versions.


The following below is an example which demonstrates the usage of the built-in PHP mysqli_stmt_data_seek() function (in a procedural style) -

   $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("Table Created.....\n");
   mysqli_query($con, "INSERT INTO myplayers values(1, 'Kennedy', 'Nkpara', 'PortHarcourt', 'Nigeria')");
   mysqli_query($con, "INSERT INTO myplayers values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");
   mysqli_query($con, "INSERT INTO myplayers values(3, 'Queen', 'Douglas', 'Texas', 'UnitedStates')");
   print("Record Inserted.....\n");

   //Retrieving the contents of the table
   $stmt = mysqli_prepare($con, "SELECT * FROM myplayers");

   //Executing the statement

   //Binding values in result to variables
   mysqli_stmt_bind_result($stmt, $id, $fname, $lname, $pob, $country);

   //Storing the result

   //Moving the seek
   mysqli_stmt_data_seek($stmt, 2);
   print("Id: ".$id."\n");
   print("fname: ".$fname."\n");
   print("lname: ".$lname."\n");
   print("pob: ".$pob."\n");
   print("country: ".$country."\n");

   //Closing the statement

   //Closing the connection


When the above code is executed, it will produce the following result -

Table Created.....
Record Inserted.....
Id: 3
fname: Queen
lname: Douglas
pob: Texas
country: UnitedStates


In an object oriented style the syntax of this function is $stmt->data_seek(); Following is the example of this function in an object oriented style -

   //Creating a connection
   $con = new mysqli("localhost", "root", "password", "mydb");

   $con -> query("CREATE TABLE Test(Name VARCHAR(255), AGE INT)");
   $con -> query("insert into Test values('Kennedy', 27),('Paul', 30),('Justice', 28)");
   print("Table Created.....\n");
   $stmt = $con -> prepare( "SELECT * FROM Test");

   //Executing the statement

   //Binding variables to resultset
   $stmt->bind_result($name, $age);


   //Moving the seek

   print("Name: ".$name."\n");
   print("Age: ".$age."\n");

   //Closing the statement

   //Closing the connection


When the above code is executed, it will produce the following result -

Table Created.....
Name: Justice
Age: 28

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the mysqli_stmt_errno() Function in PHP.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain