Fatal Error: Call to Undefined Method MySQLi_Result::Fetch_All()

Fatal error: Call to undefined method mysqli_result::fetch_all()

mysqli_result::fetch_all() requires MySQL Native Driver (mysqlnd).

chances are you might be missing it.

have a look at this posts, that might help you.

mysqli fetch_all() not a valid function?

Uncaught Error: Call to undefined method mysqli_stmt::fetchAll()

This is because there is no such function! You are mixing PDO and mysqli.

If you want to fetch all records from a mysqli prepared statement you need to do it in two steps. First, fetch the result set using mysqli_stmt::get_result() and then use mysqli_result::fetch_all()

$query = "Select * from tblorders";
$stmt = $connection->prepare($query);
$stmt->execute();

$resultSet = $stmt->get_result();
$data = $resultSet->fetch_all(MYSQLI_ASSOC);

However, I would strongly advise learning PDO instead of mysqli as it is much easier and offers more options.

Call to undefined method mysqli_result::fetch()

The variable $stmt is an object of the mysqli_stmt class. This class has a method called fetch() which returns a boolean (true/false). It is used only in conjunction with bind_result()

$stmt = $conn->prepare('SELECT myCol, myOtherCol FROM myTable WHERE dt=?');
$stmt->bind_param("s", $date);
$stmt->execute();
// The columns in SQL will be bound to the PHP variables
$stmt->bind_result($variable1, $variable2);
while ($stmt->fetch()) {
// This will fetch each record from the prepared statement one by one
printf ("myCol is %s and myOtherCol is %s\n", $variable1, $variable1);
}

$stmt->get_result() returns an object of class mysqli_result (which by the way is traversable using foreach). This class has different methods, but it doesn't have fetch() method.

  • fetch_all() return an array of arrays. As the name suggests it returns all records from the result set at once.

    $result = $stmt->get_result();
    $allRecords = $result->fetch_all(\MYSQLI_ASSOC);
    echo json_encode($allRecords);
  • fetch_array() returns each record one by one as an 1D array

    $row = $result->fetch_array();
    printf("%s (%s)\n", $row["myCol"], $row["myOtherCol"]);
  • fetch_assoc() is the equivalent to fetch_array(\MYSQLI_ASSOC)
  • fetch_row() is the equivalent to fetch_array(\MYSQLI_NUM)
  • fetch_object() returns each record one by one as an object.

    $row = $result->fetch_object();
    printf("%s (%s)\n", $row->myCol, $row->myOtherCol);

However, to keep it simple you can just loop on the mysqli_result directly which will get you each row as an associative array.

foreach($stmt->get_result() as $row) {
printf("%s (%s)\n", $row["myCol"], $row["myOtherCol"]);
}

Call to undefined method mysqli::mysqli_fetch_all() after changing server

Actually you are overwriting your variable $returnResult again and again in loop,do like below:-

$returnResult = array(); // array variable
if(!$errors) {
if( $result = $mysqli->query($addresult) ) {
while($row = $result->fetch_assoc()) // use fetch_assoc here
{
$returnResult[] = $row; // assign each value to array
}
}
}

Note:- i saw your jquery code in comment,so just change one line in above code:-

$returnResult[] = array_values($row);

PHP Fatal error: Call to undefined method mysqli::mysqli_fetch_all()

Only $result has that method. If you want to use it in a while loop use fetch_assoc(). fetch_all() returns an associative array with all the data already.

while($row = $result->fetch_assoc()){

}

mysqli fetch_all() not a valid function?

This function is available since PHP 5.3.0. Possibly your version is older. Use fetch_assoc() instead.

while ($row = $result->fetch_assoc()) {
// do what you need.
}


Related Topics



Leave a reply



Submit