I installed Microsoft SQL Server 2014 (x64)-Express and install the SQL Server Drivers for PHP 7, did changes in php.ini file also, still i am getting error while connecting php to mssql server database 'connection failed. could not find the driver'. Please help me to solve this error.
In my case, in order to access a MS SQL server database from PHP I had to do the following:
Have a PHP version installed that is compatible with microsoft SQL Server executables. Install PDO, PDO_sqlsrv driver and PDO_odbc driver.
Check the following link for instructions on how to install it.
https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver16
Related
Recently our SQL Server database has been upgraded and my PDO driver stoped working.
Currently im getting error:
SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for
SQL Server to communicate with SQL Server. Access the following URL to
download the ODBC Driver for SQL Server for x64:
https://go.microsoft.com/fwlink/?LinkId=163712
When i connect to the db via MSSMC I see:
Operation System: Microsoft Windows NT 6.3 (14393)
Platform: NT x64
Version: 13.0.5292.0
and my PHP server runs on:
Linux x64
PHP Version 7.2.5
Thread Safely: disabled
Currently PDO Driver is loaded for SQLSRV in version 5.8.0
All was working to recently just fine, from noe on just stopped with that error :(
Can I kindly ask you to help me choose the correct driver file?
from the link in the error its very confusing to choose which .so file it realy should be used.
Thank you
I was struggling to connect my Drupal (7.43) application (hosted on a PHP 5.4 server) to a Microsoft Azure SQL database.
I got really depressed and even found myself arguing with my company's DBA for why did you install this database on the newest version of SQL Server?.
Edited:
The reason why I asked that was because of Microsoft official documentation which says one should not connect to newer versions of SQL Servers if PHP server version is under 7.*.
System Requirements for the Microsoft Drivers for PHP for SQL Server
https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15#driver-versions
According to this article, if PHP server version is 5.4, the official MS driver for such php server is 3.2 version. Therefore, if the SQL Server driver is 3.2, it should not connect to SQL Server version higher than 2014.
TL; DR;
I used FreeTDS to connect 5.4 PHP application to Azure SQL Server! Yaay
FreeTDS is re-implementation of C libraries originally marketed by Sybase and Microsoft SQL Server. It allows many open source applications such as Perl and PHP (or your own C or C++ program) to connect to Sybase or Microsoft SQL Server.
My operational system is CentOS 7.
I installed basic yum packages for http server and php database connection.
yum install httpd httpd-tools php php-common php-cli php-odbc php-pdo unixODBC unixODBC-devel
So far I understand:
PDO stands for PHP Data Objects.
ODBC stands for Open Database Connectivity -- which is a standard application programming interface for accessing database management systems.
Alright, I then installed FreeTDS:
yum install epel-release
yum check-update
yum install freetds freetds-devel
Then I had /etc/freetds.conf:
[MYCLIENT]
host = myclient.database.edtech.com
port = 6669
tds version = 8.0 # Btw, how important is this version for old PHP servers versus new SQL servers?
I also had /etc/odbcinst.ini
[FreeTDS]
Driver = /lib64/libtdsodbc.so.0
FileUsage = 1
Furthermore, I had /etc/odbc.ini:
[MSSQLServer]
Driver = FreeTDS # Yes, ODBC will use FreeTDS, I get it.
Description = MSSQL Server
Trace = Yes
Server = myclient.database.edtech.com
Port = 6669
TDS_Version = 7.1 # Shouldn't this be same as the version in /etc/freetds.conf?
Database = ApplicationDB
Conclusions
I hope this question helps others.
FreeTDS is a different driver
than Microsoft's.
PHP does not know about FreeTDS not FreeTDS knows
about PHP version.
As far as I understood from the answers, there is
a ODBC bridge/layer in between them.
Better use the newest FreeTDS
version to make sure the connection works.
You said
The reason why I asked that was because of Microsoft official documentation which says I cannot connect to newer versions of SQL Server if my PHP version is below 7.*.
and
Is this php 5.4 connection really supposed to work with newest SQL
Server despite the official Microsoft docs say it should not?
...but actually, the Microsoft documentation you're talking about doesn't say you can't connect to SQL Server from PHP 5.4.
They said you can't (or at least you are not supported to) do that by using the Microsoft Drivers for PHP for SQL Server - which is the specific product that documentation is talking about.
FreeTDS is a different driver. By replacing the driver, you've replaced the thing which Microsoft is saying you shouldn't use. AFAIK Microsoft have no involvement with FreeTDS, so what they support, and what their driver works with, is entirely up to them.
I'm getting error of PDO cannot find driver using PDO in environment. I'm using xamp on a Mac.
I had got to know the problem and I've installed freetds using homebrew install, and had successfully connected to the azure mssql server using below command
tsql -H 234fddfg.database.windows.net -p 1433 -U dbuser -P db123!
but I don't know what to do next.
I've tried below php code but I'm still getting the same error.
$dbh = new PDO("sqlsrv:Server=localhost;Database=mydb", "dbuser", "db123");
Driver for Microsoft SQL Server for PHP is needed to be installed for this.
Follow this link:
https://www.microsoft.com/en-in/download/details.aspx?id=20098
Perform the following steps to download and install the Microsoft Drivers for PHP for SQL Server (example below for 3.2 version):
1. Download SQLSRV32.EXE to a temporary directory
2. Run SQLSRV32.EXE
3. When prompted, enter the path to the PHP extensions directory
4. After extracting the files, read the Installation section of the SQLSRV32_Readme.htm file for next steps
Now just add the following line to your PHP.ini (this is for the non-thread safe version of PHP, which you are most likely using when you have installed PHP to use IIS FastCGI, which we recommend):
extension=php_sqlsrv.dll
And Restart server
Have you installed PDO_DBLIB, it seems that in OSX, we need to leverage PDO_DBLIB as the pdo driver connecting to MS SQL, e.g.
$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname", "$dbuser","$dbpwd");
you can refer to Configure PHP environment on Mac to connect to SQL Server using PDO interface for more information.
I'm trying to connect a new project CakePHP v3 installed in a common LAMP on Ubuntu Server and the DataBase is a MSSQL 2008. I've tried to install the library php5-mssql but nothing changes. Any idea?
The error message received is:
CakePHP is NOT able to connect to the DataBase.
DataBase driver Cake\Database\Driver\Sqlserver cannot be used due to a missing PHP extension or unmet dependency
Thanks!
CakePHP does not have an ODBC driver at this time. You can connect to MSSQL servers using the SQLServer driver from a Windows server, but this issue (https://github.com/cakephp/cakephp/issues/6990 ) just keeps getting bumped.
Since Cake3 uses PDO drivers to connect SQL Server (from Linux), you should try to install Microsoft ODBC Driver for Linux, see
http://onefinepub.com/2013/03/ms-sql-odbc-ubuntu/
it may helps
I wanted to setup a database connection from PHP to SQL server 2012.I have a wamp server(64 bit) set up on a windows machine(64 bit) with PHP 5.5.12 and on the same machine I have SQL server 2012 installed.
Extracted sqlsrv drivers from official_link
Copied the extracted drivers php_sqlsrv_55_ts.dll, extension = php_pdo_sqlsrv_55_ts.dll to php\ext folder, and then changed the php.ini file to include the extensions
extension = php_sqlsrv_55_ts.dll; extension = php_pdo_sqlsrv_55_ts.dll;
Now I tried
<?php
phpinfo();
?>
I see the following information without any SQL server information in it.
Don't seem to have configured SQL server connection successfully. Could some one please guide me on what I am missing here.
64 bit WAMP server was not able to connect using the drivers extension = php_sqlsrv_55_ts.dll; extension = php_pdo_sqlsrv_55_ts.dll;
So, I installed a 32 bit version of the WAMP server and it works fine now.
Check the php error log (c:\wamp\logs\php_error.log).
I had the same setup (64bit WAMP/PHP 5.5.12) and same missing sqlsrv reference in phpinfo and I got this error in my log:
PHP Warning: PHP Startup: Unable to load dynamic library
'c:/wamp/bin/php/php5.5.12/ext/php_pdo_sqlsrv_55_ts.dll' - %1 is not a
valid Win32 application. in Unknown on line 0
The solution was to install the 64bit version of the sqlsrv drivers. I found the unofficial 64bit drivers through http://robsphp.blogspot.nl/2012/06/unofficial-microsoft-sql-server-driver.html
Warning: In my testing I found these 64bit PHP_PDO_SQLSRV extension 10 times slower than when using PHP_PDO_ODBC.
I am visiting this thread and i think this might help full for you and other with the same issue:
How can I install pdo_sqlsrv on my windows 2008 Server 2008 R2?
The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable
extension=php_pdo_mssql.dll
in your php.ini.
{Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/ and just take the extension from a package there (take one that correspond with your PHP version of course)}.
Above is taken from PDO MSSQL Server - Driver not found
read for more details. i have the same issue foe linux and i have saved all the pages thats why i am quoting for you help.
if all above didn't work for you then:
On the php.net it is listed that
On Windows, PDO_ODBC is built into the PHP core by default. It is linked against the Windows ODBC Driver Manager so that PHP can connect to any database cataloged as a System DSN, and is the recommended driver for connecting to Microsoft SQL Server databases.
http://php.net/manual/en/ref.pdo-odbc.php
You can connect to mssql server using odbc drivers as i have never connect by my self from windows i use to do it through linux using freeTds, following pages might help you
http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/
Connect PHP to MSSQL via PDO ODBC
PHP to SQL Server without ODBC or MSSQL support