0

I'm dealing with an issue where the mysqli library in PHP doesn't seem to return a longtext column. I can get the value of the column using both console and PHPMyAdmin but mysqli returns nothing but an empty string.

Here's the function I'm using:

public function greetings_get() {
        $output = array();
        $greetings_query = "SELECT `engagement_data`.`data`, `engagement_users`.`name` FROM `engagements`, `engagement_data`, `engagement_users` WHERE `engagements`.`promo_slug` = 'stod2.hm2013' and `engagements`.`user_fbid` = `engagement_users`.`fbid` and `engagement_data`.`engagement_id` = `engagements`.`id` ORDER BY RAND() LIMIT 0,5";
        $greetings = $this->db_connection->prepare($greetings_query);
        $greetings->execute();
        $greetings->bind_result($gr_data, $gr_name);
        while ($greetings->fetch()) {
                $output[] = array('message' => $gr_data, 'name' => $gr_name);
        }
        return $output;
}

In this case, $gr_data is an empty string, while $gr_name returns a value. –Strange isn't it?

Is there something I'm doing wrong?

aldavigdis
  • 635
  • 6
  • 17

1 Answers1

3

According to this answer at php.net, you must use mysqli_stmt::store_result before you bind the result

When using prepare to prepare a statement to retrieve LOBs the method order matters. Also, method 'store_result()' must be called and be called in correct order. Failure to observe this causes PHP/MySQLi to crash or return an erroneous value.

This

$greetings->execute();
$greetings->store_result();
$greetings->bind_result($gr_data, $gr_name);

should fix it.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198