1

I hope you can help me with this.

I used:

  1. Mysql workbench 5.6 with ( 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', )
  2. Laravel 5.4

I have a controller (GetDataController.php)that will call stored procedure, below is the code:

function getData(){
    $data= DB::select('call spGetAllData()');
    return Response::json(['message' => $data], 200);
}

api.php

Route::get('showAllData','GetDataController@getData)

The result after accessing it via browser:

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������{"message":[{"ID":1,"Data":"data001"},{"ID":2,"Data":"data002"},{"ID":3,"Data":"data003"}]}

Tried using utf8_encode(),json_decode/encode but still no luck.

EDIT FOR dd($data) result;

array:3 [▼
  0 => {#221 ▼
    +"ID": 1
    +"Data": "data001"
  }
  1 => {#224 ▼
    +"ID": 2
    +"Data": "data002"
  }
  2 => {#226 ▼
    +"ID": 3
    +"Data": "data003"
  }
]
jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
iamj
  • 173
  • 1
  • 10
  • What does $data look like? Just do a dd($data). – Mick Apr 05 '17 at 09:53
  • @Mick I will edit my post to show the result of dd($data) – iamj Apr 05 '17 at 10:00
  • @Mick see edits above – iamj Apr 05 '17 at 10:04
  • Does it work ok, if you just do a SELECT? I don't think many people use stored procs with Laravel. I do it like this, maybe try this: ```return response()->json(['error' => 'No faults assigned to this process/stream.'], 404);``` – Mick Apr 05 '17 at 10:38
  • do you mean raw queries? not using SP? – iamj Apr 05 '17 at 10:42
  • Yes, a raw ```SELECT * FROM``` or use Eloquent. Most Laravel developers use Eloquent. – Mick Apr 05 '17 at 10:45
  • Tried raw queries ,eloquent and return response()->json(['error' => 'No faults assigned to this process/stream.'], 404); still ��� are showing – iamj Apr 05 '17 at 10:47
  • 1
    See "Black diamond" in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Apr 09 '17 at 04:03
  • I already fixed this problem. I exported new dump file from other server and set my schema to UTF-8 default collation – iamj Apr 24 '17 at 14:19

0 Answers0