- Cài đặt FreeTDS
$ apt-get install libsybdb5 freetds-common php5-sybase
- Thêm cấu hình trong config/database.php trong Laravel 5
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
]
- Sử dụng thêm DB::raw("N'Phạm Văn Trung'") vào trường tiếng viêt trong database
DB::table('users')->insert([
'name' => DB::raw("N'Phạm Văn Trung'"),
'username' => 'trungpv93',
'email' => 'email@gmail.com',
'password' => bcrypt('ABCXYZ'),
]);
$user = new User();
$user->name = DB::raw("N'Phạm Văn Trung'");
$user->username = 'trungpv93';
$user->email = 'email@gmail.com';
$user->password = bcrypt('ABCXYZ');
$user->save();
- Note (Option): Nếu có vấn đề về tiếng việt thì sửa lại tds version trong /etc/freetds/freetds.conf
tds version = 8.0
client charset = UTF-8
=>
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2
tds version = 8.0
client charset = UTF-8
...........................