@noleafclover614, Sorry, the right way of doing it is by setting the right timezone in your app.php config file:
// app.php
'timezone' => 'America/Mexico_City',
That's it!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
@noleafclover614, Sorry, the right way of doing it is by setting the right timezone in your app.php config file:
// app.php
'timezone' => 'America/Mexico_City',
That's it!
@uxweb have set up my laravel app in a vps server where i added the freetds dev package. From there, i added the database credentials in the freetds configuration file.
The database is located in a cloud sql server with a public ip assigned to it.
So when i connect to public ip with the database credentials i see the sqlserver tables.
http://support.microsoft.com/en-us/kb/173907
http://www.unixodbc.org/odbcinst.html
Hi, Here are some URLs for SQL server. Basically SQL Server is SYBase. Only with Microsoft extensions. TDS is ther network transfer protocol. TSQL or Transact SQL is the dialect it uses. You have all the basic sql syntax plus command stuff. Some where on your ubuntu box is an .ini file, usually its called odbc.ini, but it can be called anything set on your ernvironment. In your ini file I am pretty almost sure you can set the defaults for various formats. Each connection ion an ini file starts with [Database] Database is just the connection name you give it. Look at the ibm link I pasted. You will see an INI entry for date format set to 1. Probably USA. Anyway it is sleepy time for me but saw your plight. While its been awhile I have used Sybase/MS-SQL on every UNIX/Linux box mI can think of. They all look the same.
Google for things like: odbc.ini default date format
You can also set the default date format per connection. See first pasted link from dear old Microsoft. The Sql raw should handle that for you.
look in your etc dir or dirs for configs...
@noleafclover614 I just ran into the same problem with the times being off. Switching the locale date format from
date format = %b %e %Y %I:%M:%S:%z%p
to
date format = %b %e %Y %H:%M:%S:%z
will use 24 hours instead of 12 hours with AM/PM
@uxweb The SQLSRV extension seems only works on Windows servers from php.net documentation.
@dlenzin Yes!, but in linux we have dblib which uses freetds or odbc.
Laravel checks for the available database drivers for sql server, if it finds that sqlsrv exists (windows) it will use it, else, it will use dblib (linux).
I use the following recipe on Forge and Homestead (after.sh) w/o problems or any additional configuration for MS SQL.
sudo apt-get install php5-sybase -y
So what worked for me, on an Ubuntu 14.04 server was
sudo apt-get install php5-mssql
followed by creating /etc/freetds/locales.conf with the following contents:
[default]
date format = %Y-%m-%d %I:%M:%S.%z
followed by restarting apache
sudo service apache2 restart
Now the driver works and Laravel no longer barfs when it reads date/time fields.
Hi All I have MS-SQL Database for the Laravel5 which is in Linux platform(AWS-RDS).Laravel5 supports sqlsrv driver but sqlsrv doesn't get supported on Linux platforms.
I have tried FreeTDS driver and database connection is not happening. What should I do now?
I've given up hope for SQL Server on Linux.
On a related note: If you're looking to move your application to PHP 7 when in launches, you're going to struggle to get any driver before 2016 (at the earliest). https://github.com/Azure/msphpsql/issues/58
It has been hard for the community to get answers from them on timescales. Surely they knew PHP 7 was coming, and surely Azure users will want to decrease the number of application servers with the new performance that's coming?
Hi everyone,
Just posting this in case anyone seems to come past this one as PHP 7 was just released. MSSQL will work in PHP 7 and also with Eloquent. You'll just need to install the PHP 7 Sybase package. I've tested with a MS SQL Server 2008 R2 server. If you're on Ubuntu:
sudo apt-get install php7.0-sybase freetds-common libsybdb5
If anyone needs any help installing, I'd be more than happy to help.
Didn't read every reply, but could you just use Mysql? Just some exporting and importing.
@campo I'm having serious problems with setting up charset. I've checked every config many many times and tried many different variations. This problem actually occurred after some FreeTDS update in Spring 2015.
Now I'v setup local Homestead box with using remote SQL connections. Eloquent just gets blank object or gives 207 error. Though some queries for like session login.
I've read debug dump logs and everything seems to be working. Somewhere along the line, perhaps on PHP config + Eloquent region, encoding gets messed up.
@campo Thank you for providing that command, it helped to get everything installed. I think I'm missing something though because my application is still saying that mssql isn't installed. What did you other than run the command you provided to get this working in Homestead?
@envision are you setting it to UTF-8 in the freetds configuration file located in /etc/freetds?
@dnewbytricore No problem buddy. To answer your question, you can't use the native mssql_* functions, you'll need to use dblib w/ PDO. Eloquent works out of the box. If you're not using Eloquent here's a quick gist to show you how to use PDO: https://gist.github.com/joecampo/acd1e5881aee08bd8959
@campo actually there is an ongoing problem with this setup not yet resolved. A year ago after updating CentOS packages the Eloquent database connection got broken. For some simple queries it might work but most of the time gets empty result. I suspect this to be an encoding related issue.
There is already a week's worth of work behind debugging this and it hasn't resolved, on hold at the moment. Last month I tried again, this time with the newest Laravel 4.2 system as well as an empty L 5.2 project – neither of them works. And this time it was tried on Homestead (Ubuntu) instead of CentOS.
Thanks for the tips in this thread. If any of you have a working setup from homestead/linux using php7 I would like to learn the server config and preferrably also a simple query code example, had no luck with either sybase or unixodbc.
This issue comment mentions there will be a driver out for testing within a month. https://github.com/Azure/msphpsql/issues/58#issuecomment-193665142
Let's hope the announcement of MS SQL Server on Linux is going to provide solutions http://blogs.microsoft.com/blog/2016/03/07/announcing-sql-server-on-linux/
@campo I'm getting a 404:
Err http://ppa.launchpad.net/ondrej/php/ubuntu/ trusty/main php7.0-sybase amd64 7.0.5-2+deb.sury.org~trusty+1 404 Not Found [IP: 91.189.95.83 80] E: Failed to fetch http://ppa.launchpad.net/ondrej/php/ubuntu/pool/main/p/php7.0/php7.0-sybase_7.0.5-2+deb.sury.org~trusty+1_amd64.deb 404 Not Found [IP: 91.189.95.83 80]
@campo thank you for this - I was literally searching for hours!
sudo apt-get install php7.0-sybase freetds-common libsybdb5
That said, after running the above I was still running into some problems in that the standard MSSQL response error messages doesn't get returned and instead all I was getting back was the following "SQLSTATE[01002] Adaptive Server connection failed (severity 9)".
(Turns out my password was incorrect of all things!)
For those wanting to do some debugging around these kinds of errors make sure to enable the "dump file = /tmp/freetds.log" option under the "[global]" section of the freetds.conf file. Then hunting through this log will give you the error that the MSSQL server returns back to the TDS requst.
On that note I also had to change my TDS Protocol version from the default 4.2 up to 7.2 and I had to include the "client charset = UTF-8" option as well.
My final freetds.conf global section looks as follows:
[global] tds version = 7.2 client charset = UTF-8 dump file = /tmp/freetds.log
@matthewfritz all good tips! I think it's also worth mentioning that Microsoft is working on an official PHP7 driver for MSSQL that is now in Early Technical Preview status: https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux
Actually my associate pointed out that Microsoft does have alternative to FreeTDS driver...and I don't recall anymore why I chose to go with FreeTDS route.
Anyone has experience with this driver instead of FreeTDS on Linux?
https://msdn.microsoft.com/en-us/library/hh568451(v=sql.110).aspx
Hey all. I've been using https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux#install and it's never failed me. It's straight forward. Use the nts version.
For anyone that is still on Ubuntu 14.04 - although the installation guides for the official driver mention 15 & 16 only, it will work on 14.04.
Here's a bash script I put together to help automate the installation process. This process assumes that you're using PHP7.0 (preferably from the ondrej ppa as you'll need to install php7.0-dev to use phpize).
https://gist.github.com/joecampo/6f777a659b8132b9d6fe1c3589df394c
The beautiful thing about Laravel is that you can upgrade your production servers pretty silently from the old FreeTDS/dblib MSSQL implementation to the new official driver
The SqlServerConnector class in Illuminate\Database\Connectors will use dblib if available and won't fall to using sqlsrv unless dblib is disabled.
protected function getDsn(array $config)
{
// First we will create the basic DSN setup as well as the port if it is in
// in the configuration options. This will give us the basic DSN we will
// need to establish the PDO connections and return them back for use.
if (in_array('dblib', $this->getAvailableDrivers())) {
return $this->getDblibDsn($config);
} elseif ($this->prefersOdbc($config)) {
return $this->getOdbcDsn($config);
} else {
return $this->getSqlSrvDsn($config);
}
}
So my installation process is as follows:
php -r '
echo "+ Connection\n";
$pdo = new PDO("sqlsrv:Server=server", "username", "password");
echo "+ Query\n";
$query = $pdo->query("SELECT @@version");
if ($query) {
echo "+ Result\n";
$row = $query->fetch(PDO::FETCH_NUM);
if ($row) {
print_r($row);
}
}
'
@campo I've got following errors while running your scripts.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_sqlsrv.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PDO drivers => dblib, mysql, pgsql, sqlite
any idea?
-edit-
It occured on homestead machine and the reason was mapped directory doesn't exists.
I made directory named msphpsql-4.0.6-Linux at /home/vagrant and it works fine.
In case you need must update information https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu/
I'm having a bad time with SQLSRV on a Forge-deployed Ubuntu box:
https://laracasts.com/discuss/channels/forge/cant-get-sqlsrv-pdo-to-connect-to-remote-sql-server
https://stackoverflow.com/questions/48651225/cant-get-sqlsrv-pdo-to-connect-to-remote-sql-server
@campo thank you! disabling the dlib extension did the trick for me!
Please or to participate in this conversation.