the following error is thrown:
Fatal error: Trying to clone an uncloneable object of class mysqli_result
when I'm trying to use clone directly for a mysql query result:
$result = mysqli_query($con, $query);
$resultsClone = clone $result;
is there a way to clone mysqli object?
Cloning an unclonable object is not possible, as the name suggests.
Just because to tell a little bit more: In this specific case a mysqli
-result is (more or less -- I don't know the exact details) a pointer to a result "somewhere else". Cloning would mean, that two pointers referes to the same result "somewhere else", what again will probably lead to severe side effects, because fetching results from one result will definitely affect the other one.
As KingCrunch already explained, there is not much use in cloning database result pointers - they have a limited context in which they live - as any pointer or resource.
Depending on what you want to do however, you can just run the query a second time:
$result = mysqli_query($con, $query);
$resultClone = mysqli_query($con, $query);
Or you encapsulate the fetch logic so that you rewind on the same resource depending on the state of your application.
Move the pointer (return) to the zero line of the result. http://www.php.net/manual/ru/mysqli-result.data-seek.php