0

running my query below works fine when running in phpmyadmin

SELECT * FROM `outbox_pending` ORDER BY `id` ASC LIMIT 25

It brings back

The offer Butlers Bingo - Deposit £10 Play 60has been completed by from the source .

However, using this in my php code it brings back everything else, but shows NULL instead of this text.

I've worked out it's the pound symbol causing the issue. So, I went and changed the Collation to utf8_general_mysql500_ci and it's still not showing (I've also tried some others too).

Any ideas?

PHP Code

function viewPendingMsgs() {
    // views all messages from database
    include_once('db.php');

    $sql = "SELECT * FROM `outbox_pending` ORDER BY `id` ASC LIMIT 25";
    $result = $conn->query($sql);

    //echo $sql

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            $rows[] = $row;
        }
    print json_encode($rows);
    } else {
        //echo $sql;
        echo json_encode(array('status'=>'fail'));
    }
    $conn->close();
    }

Output

[{"id":"95","to":"0755XXXXXXX","msg":null,"ip":"107.66.31.214","datetime":"September 19, 2016, 6:14 am"}]

BCLtd
  • 1,459
  • 2
  • 18
  • 45
  • What is your connection character set with mysql? Are you using SET NAMES to set it after connecting to your db? Also are you displaying this information in an html page? – Andreas Sep 19 '16 at 16:55
  • Can you show the PHP code? If you swap the `£` out of that row it returns the data successfully? If it was an encoding issue I would expect the `£` to just be rendered incorrectly. – chris85 Sep 19 '16 at 17:41
  • added :) - it just comes back null – BCLtd Sep 19 '16 at 17:58
  • In your connection you are setting it to UTF8? This sounds a lot like http://stackoverflow.com/questions/1972006/json-encode-is-returning-null, look at Nobert's answer there, seems more useful to me; http://stackoverflow.com/a/1972468/4333555. – chris85 Sep 19 '16 at 21:27

0 Answers0