-1

I'm facing a horrible problem in Linux server. I don't understand what to do now.

My problem is that in Linux server my script runs properly without any error but when I use an object to JSON encode it returns false.

Please any one help. Thanks in advance.

public function ajaxDataSearch() {
    $this->loadModel('ViewDocketHistorys');
    $this->render(false);
    $this->viewBuilder()->layout('false');
    if ($this->request->is(['post'])) {
        $DocketNo = $this->request->data['DocketNo'];

       $SearchData = $this->ViewDocketHistorys->find()
                ->where(['DocketNo' => $DocketNo])
                ->last();
        $Jsondate = json_encode($SearchData);
        echo $Jsondate;
    }
}

When I debug query data

debug($SearchData); exit;

output:

object(App\Model\Entity\ViewDocketHistory) {
'MasterID' => (int) 311,
'DocketNo' => 'fhfghfghf',
'[new]' => false,
'[accessible]' => [
    '*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ViewDocketHistorys'}

When I debug JSON encode

debug($Jsondate); exit;

Output:

false
4
  • Debug the problem by checking json_last_error() and json_last_error_msg() after calling json_encode(). Commented Jul 12, 2017 at 19:36
  • its says error 8 (Type not supported) Commented Jul 13, 2017 at 11:46
  • Good, now inspect $SearchData->jsonSerialize() to figure what the unsporrted type may be. Commented Jul 13, 2017 at 16:38
  • I found the data type problem in database, Some column convert BLOB data type when run database in Linux server but still working in windows server, I thing that BLOB data type is the main problem i found. Now the problem is why my column convert BLOB form in view table, I selected int data type but that converted BLOB data type when creating view in Linux and varchar(255) in windows, I check all table column that are same but don't understand why its converted, if you find this problem please help me, that is the 4th day facing the bullshit problem. Sorry and Thank you Commented Jul 16, 2017 at 6:24

2 Answers 2

0

Last found a solution When I create a view with a UNION, i have to make sure the data types of the corresponding columns are the same (or at least, similar enough for one to be converted to the other). In the current case, the first column of the view is a 'column1', and no data type definition apart from BLOB can make much sense of that.

If you really need this as a view, you could try...

SELECT e.ID AS ID, 
   NULL        AS table_field,
   ...etc...
   'e'         AS type
FROM table1 AS e
 UNION ALL
 SELECT
    NULL         AS ID,
    k.table_field AS table_field, 
   ...etc...
   'k'          AS type
 FROM table2 AS k;

Details here

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

Comments

0

You can try by doing:

$Jsondate = json_encode($SearchData->toArray());

->toArray() will convert entity class into a clean array, after that, json_decode would receive the right structure to JavaScript Object Notation.

1 Comment

i am trying but my problem is data field, and that's problem solved it, i posted before comment.

Your Answer

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