How to setting to use SQL Server in Laravel

When I setup Laravel project for my company, I’ve faced the problem about SQL Server database connection problem. I’ve googled and now I can use it.

1. Install php7.0-sybase to Homestead

New version of Homestead uses php7.0 to serve laravel website. So, I installed php7.0-sybase using bellow command.

2. Edit /etc/freetds/freetds.conf file

I don’t know about TDS but I followed reference bellow,

Also create /etc/freetds/locales.conf file to allow correct parsing of dates.

3. add getDateFormat() function to each Model classes

Eventhough I already set the datetime format from above, I still got the Data missing error when access Carbon class.
This is because the difference of datetime string format. My SQL Server gives '2016-06-20 13:00:00' datetime string to Laravel, but Carbon accepts 'Y-m-d H:i:s.000' format to create instance.

So, add getDateFormat() function to each Model classes to give format information.

SqlServerGrammer.php file returns Y-m-d H:i:s.000 DateFormat. Change it to Y-m-d H:i:s to apply all models or just delete this function. Because Grammer.php abstract class returns Y-m-d H:i:s format…



You may also like...

Leave a Reply