Laravel 5 + SQL Server and encoding errors

I am using Laravel 5 and SQL Server to get some data.

Whenever the data has some special characters (éê etc.), Laravel does not show the column value as if it were just nothing. (also not null).

I tried some SQL commands via tinker and got the same results. My titles don't show up when they have special characters.

The database is encoded with this collation: Latin1_General_CP1_CI_AS And my database.php looks like this:

<?php
      return [
      'connections' => [
                'mysql' => [/*my mysql connection*/],
                'dbmssql' => [
                            'driver'    => 'sqlsrv',
                            'host'      => 'host',
                            'database'  => '',
                            'username'  => 'username',
                            'password'  => 'password',
                            'prefix'    => '',
                            'collation' =>  'SQL_Latin1_General_CP1_CI_AS',
                            'charset'   =>  'latin1'
                        ],
                ]
      ];

      

We've tried almost everything. Changing collation / encoding, adding "Cast ()" to our SQL commands, etc. None of them work. We can't even get data with bad encodings. It just doesn't return anything.

Here is the tinker result:

  • The first result was added via Laravel, so the coding works with Laravel, but it's poorly coded on SQL Server
  • The second result has no special char. and display normally on both sides
  • The third result has a special char. on SQL Server Laravel doesn't render it at all.
      id: "1",
      titre: "ûéÉàÀêÊïÏçÇ",
      etat: "1",
      created_at: "May 29 2015 08:04:43:000PM",
      updated_at: "Jun  1 2015 03:24:44:000PM"
  },
  <stdClass #000000005a3cad49000000000aae376c> {
      id: "2",
      titre: "Administration",
      etat: "1",
      created_at: "Jun  1 2015 08:55:00:000AM",
      updated_at: "Jun  1 2015 08:55:00:000AM"
  },
  <stdClass #000000005a3cad4c000000000aae376c> {
      id: "3",
      titre: ,
      etat: "1",
      created_at: "Jun  1 2015 08:55:00:000AM",
      updated_at: "Jun  1 2015 08:55:00:000AM"
  },

      

Has anyone come across something similar?

Thank you for your time!

UPDATE

I finally did it using mutators!

Here is my code in case anyone comes across this situation.

<?php
#In my Model file.

public function getTitreAttribute($title){
    return utf8_encode($title);
}

public function setTitreAttribute($titre){
    $this->attributes['titre'] =  utf8_decode($titre);
}

      

+3
php sql-server encoding laravel laravel-5


source to share


No one has answered this question yet

See similar questions:

0
Laravel collection accentuation error

or similar:

3491
How can I UPDATE from SELECT in SQL Server?
2776
How can I prevent SQL injection in PHP?
2603
Add column with default value to existing table in SQL Server
2366
Encode url in JavaScript?
1787
How can I concatenate text from multiple strings into one text string in SQL Server?
1770
How do I check if a column exists in a SQL Server table?
1658
How to return only date from SQL Server DateTime datatype
1587
Insert multiple rows into one SQL query?
1433
LEFT JOIN vs. LEFT OUTER JOIN in SQL Server
1005
Check if a table exists in SQL Server



All Articles
Loading...
X
Show
Funny
Dev
Pics