MySQLi Fetch_All() Not a Valid Function

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.
}

MySQLi fetch_all Error with Consecutive Calls

It looks like you need to reset the result pointer after a fetch_all.

I didn't find anything in the docs specifically for fetch_all - only about resetting after a fetch_assoc(), where we can find a reference to data_seek(): http://php.net/manual/en/mysqli-result.data-seek.php

So here's what you should do:

before the second fetch_all() do a

$res->data_seek(0);  // where $res is your mysqli result Object

This basicly sets the result pointer to the first record.

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.
}

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?

Call to a member function query() on a non-object error

Any idea why I'm getting this error when the $result = $conn->query($sql); tries to run??

You should read this part of documentation.

You can't use $conn variable inside function like that. All variables used inside function must be either passed as arguments or declared in function body.

tldr: Just move $conn = test_connect(); into body of function test.

PHP while code error

if you want fetch without index use mysqli_fetch_assoc().

Or

if you want to fetch with index use mysqli_fetch_array()

And i think you are doing wrong here because your table tag is inside while loop and your <thead> too.
i think it should be outside of while loop. and you have syntax error in your query and you have one extra <th>

your full code.

<?php 
$host="localhost";
$user="root";
$pwd="";
$db="assigment";
$conn=mysqli_connect($host,$user,$pwd,$db);
$query="SELECT * FROM tdata ";
$result=mysqli_query($conn,$query); ?>
<table class="table">
<thead>
<tr>
<th>Full Name</th>
<th>Email</th>
<th>Birthday</th>
<th>Gender</th>
<th>Intrests</th>
<th>Address</th>
</tr>
</thead>

<tbody>
<?php while ($row=mysqli_fetch_assoc($result)) { ?>

<tr>
<td><?php echo $row['full_name']; ?></td>
<td><?php echo $row['your table field name']; ?></td>
<td><?php echo $row['your table field name']; ?></td>
<td><?php echo $row['your table field name']; ?></td>
<td><?php echo $row['your table field name']; ?></td>
<td><?php echo $row['your table field name']; ?></td>
</tr>
<?php }
?>
</tbody>
</table>

$result- fetch_all(MYSQLI_ASSOC) returns nothing

As mentioned in a comment to David, the problem was with fetch_all(). I guess what was making the problem is the server resources because the page returned 500 on call.

In any case I retrieved the required array using this method instead:

$conn = new mysqli($servername, $username, $password, $dbname);
$result = $conn->query("SELECT * FROM customers LIMIT 10");
$outp = array();

while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$outp[] = $result->fetch_array(MYSQLI_ASSOC);
}


echo json_encode($outp);

And it worked.

Now, I'm going to make it work with my JSON callback.



Related Topics



Leave a reply



Submit