Mysqli query returns empty results

im trying to get some data from my db using this code:

<?php error_reporting(E_ALL); ini_set('display_errors',1); $mysqli2 = new mysqli(********************); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $sql2 = "SELECT message FROM wall_workouts_names WHERE id = ? "; $stmt2 = $mysqli2->prepare($sql2) or trigger_error($mysqli2->error."[$sql2]"); $id_for_wall = '43'; $stmt2->bind_param('s', $id_for_wall); $stmt2->execute(); $stmt2->bind_result($message); $stmt2->store_result(); $stmt2->fetch(); echo $message; ?> 

My problem is that I get an empty string in my echo.

But if I run the same query in my phpmyadmin, I get good results.

thanks for the help

+4
source share
2 answers

Most likely, in your WHERE clause there is no line to match the condition, namely: id = 43

+1
source

Check your incoming results as follows.

  while ($stmt->fetch()) { echo $message; } 
-one
source

Source: https://habr.com/ru/post/1501297/


All Articles