J
J
JackShcherbakov2018-03-12 03:39:24
PHP
JackShcherbakov, 2018-03-12 03:39:24

Why is the script not outputting anything?

Hello! I want to explicitly clear the memory occupied by the query result. But for some reason, after such a procedure, nothing is displayed. What's the matter? After all, the memory was cleared after use, so there was plenty to take lines from. Here is the memory cleanup code:

<?php

$db = new mysqli("localhost", "root", "23210100", "Books");
$query = "SELECT * FROM Books WHERE Price>?";
$stmt = $db->prepare($query);
$var = 15.00;
$stmt->bind_param("d", $var);

$stmt->bind_result($isbn, $author, $title, $price);

$stmt->execute();
$result = $stmt->get_result();

while($stmt->fetch()){
  echo "$isbn, $author, $title, $price<br>" ;
}
echo "Всего строк - " . $stmt->num_rows;
$result->free();

?>

Result:
Всего строк - 0
Here it is without cleaning:
<?php

$db = new mysqli("localhost", "root", "23210100", "Books");
$query = "SELECT * FROM Books WHERE Price>?";
$stmt = $db->prepare($query);
$var = 15.00;
$stmt->bind_param("d", $var);

$stmt->bind_result($isbn, $author, $title, $price);

$stmt->execute();
//$result = $stmt->get_result();

while($stmt->fetch()){
  echo "$isbn, $author, $title, $price<br>" ;
}
echo "Всего строк - " . $stmt->num_rows;

?>

Result:
0-672-31509-2, Pruitt, et al., Teach Yourself GIMP in 24 Hours, 33.26
0-672-31697-8, Michael Morgan, Java 2 for Professional Developers, 61.98
0-672-31745-1, Thomas Down, Installing Debian GNU/Linux, 33.26
Всего строк - 3

What is the problem and how to fix it? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-03-12
@JackShcherbakov

Why didn’t you use the construction True in the first example, you while ($row = $result->fetch_assoc()) {
will have to abandon bind_params

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question