0

In progress of this issue:

Mysqli query return empty results

This is my php 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 = '43' ";

    $stmt2 = $mysqli2->prepare($sql2) or trigger_error($mysqli2->error."[$sql2]");

    $stmt2->execute();

    $stmt2->bind_result($message);

    $stmt2->store_result();

     $stmt2->fetch();

    if($stmt2->num_rows > 0)
       echo $message;    
   else
        echo 'empty';    

?>

From this code i get empty string as a result.

This is my table in phpmyadmin

enter image description here

When i run the same code but with this query:

 $sql2 = "SELECT workout_name FROM wall_workouts_names WHERE id = '43' ";

My echo is "t", as is should be.

But when i run this query:

 $sql2 = "SELECT message FROM wall_workouts_names WHERE id = '43' ";

I get empty string, something like this: "".

I dont understand what im doing wrong.

1
  • What is the return value of $stmt2->bind_result($message); ? Is it === true? Commented Sep 10, 2013 at 16:25

1 Answer 1

1

According to this commenter, the

"proper procedure order is: prepare -> execute -> store_result -> bind -> fetch."

I notice that you are calling store_result() AFTER you call bind_result(). Does changing the order of those calls make any difference?

Sign up to request clarification or add additional context in comments.

2 Comments

Have you tried other sanity checks, like selecting message and workout_name together, and selecting the message from a different record besides id 43?
I tried selecting different record, and still got empty string. BUT i tried selecting more than one column and its working, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.