Forum Moderators: coopster

Message Too Old, No Replies

Retrieving MySQL LONGTEXT data using mysqli

I am getting garbage data back

         

Captaffy

8:01 pm on Dec 10, 2006 (gmt 0)

10+ Year Member



I have some code, along the lines of the following, where the column it is selecting is of the type LONGTEXT, from a MySQL database.

$stmt = $mysqli->prepare(... LIMIT 1);
$stmt->bind_param(...);
$stmt->execute();
$stmt->bind_result($longtext_value);
$stmt->fetch();

The $longtext_value variable just contains garbage however (i.e. random symbols).

Am I doing something wrong? If I use the exact same query, but select a different column such as an INT, it works fine.

coopster

2:51 pm on Dec 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What are you storing in the LONGTEXT column that you are trying to retrieve?

Captaffy

12:53 am on Dec 12, 2006 (gmt 0)

10+ Year Member



The values stored in the column are strings, about 50 characters long. (To be specific, they are URLs.)
The database was created by WordPress and I am simply reading from it, for a different application. (If you have any experience with WordPress, the specific column is wp_postmeta.meta_value.)

Since I first posted, I have tried using the following, and it prints out the result correctly.

$stmt = $mysqli->query("SELECT ... LIMIT 1");
$row = $stmt->fetch_row();
print($row[0]);

I don't know what to make of it, but at least I have something working.

coopster

3:06 am on Dec 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm guessing you had something wrong originally when you were binding [php.net] the variable.