I am trying to connect to a remote SQL Server Windows 2008R2 and a file server Windows 2008. I am wondering what the best way is to handle this. I've tried odbc_connect and mssql_connect without any luck.
When using odbc_connect I get these errors:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified
[16-Jan-2014 16:02:12 UTC] PHP Warning: odbc_connect() [<a href='function.odbc-
connect'>function.odbc-connect</a>]: SQL error: [unixODBC][Driver Manager]Data source
name not found, and no default driver specified, SQL state IM002 in SQLConnect in
/mnt/stor12-wc1-dfw1/657080/843636/www.ia764.org/web/content/cms/wp-content/themes
/iatse/functions/syntonics.php on line 27
This is not my area of expertise so layman's terms are welcomed.
Any help/guidance would be greatly appreciated!
I had this problem, too. What you need to do is install FreeTDS so you can use the ODBC drivers. It's somewhat of an intense process if you're not familiar with linux. However, I've documented all the steps in the answers here Connect PHP to MSSQL via PDO ODBC
and here Can't Install FreeTDS via Yum Package Manager
This answer assumes you are on a linux server, not Windows.
Related
Actually, I followed all the paths in the document, but I still get an undefined sql error while connecting.
I followed these paths respectively.
1-Microsoft® ODBC Driver 11 for SQL Server® install
2-Microsoft Drivers for PHP for SQL Server this version: 7.3
dll files in the corresponding folder
php / ext
php_pdo_sqlsrv_73_nts_x64.dll
php_pdo_sqlsrv_73_ts_x64.dll
then I restarted xampp, i viewed phpinfo
But when I run my file the error I get is:
Fatal error: Uncaught Error: Call to undefined function
sqlsrv_connect() in
what could be missing?
You need to enable PHP Driver for SQL Server, but not PDO version. Function sqlsrv_connect() and all sqlsrv_ functions are part of the SQLSRV driver.
To enable the SQLSRV driver, you need to modify the php.ini by adding the appropriate line to the extension section - php_sqlsrv_73_nts_x64.dll or php_sqlsrv_73_ts_x64.dll depending on the PHP version.
Of course, as an option, you may try to rewrite your code using PDO (PHP Data Objects). The PDPO_SQLSRV part of the driver is installed on your WEB server.
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
I am using PHP 5.6.35, and I have downloaded and installed/enabled the Microsoft SQL Server Drivers for PHP. Specifically, the ones below
extension=php_pdo_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_nts.dll
I can see that they are enabled properly looking at the phpinfo() output. It shows both pdo_sqlsrv as enabled as well as sqlsrv support. However, when I try to connect to my database I get the following error back.
This extension requires the Microsoft ODBC Driver 11 for SQL Server.
Access the following URL to download the ODBC Driver 11 for SQL Server
for x86: http://go.microsoft.com/fwlink/?LinkId=163712
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified [message] => [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified )
So, I assumed I needed to download the ODBC Driver 11 for SQL Server. So I downloaded what I thought was the correct file from here.
https://www.microsoft.com/en-us/download/details.aspx?id=36434
But when I try to install the driver I get an error stating that the installation of this product failed because it is not supported on this operating system. I'm running PHP 5.6.35 on Windows Server 2016.
HELP?
Use the x64 install file. I ran into the same issue and was able to add the 32 bit driver from the x64 installation. I have a 64 bit processors and I tried to test the 32 bit install file for implementation on the x86 systems and seen the same error.
Getting the following error when testing an upgrade to PHP7 x64:
odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I've installed the following:
PHP 7.0.0 x64
Microsoft ODBC Driver 11 for SQL Server x64
Microsoft Visual C++ 2015 Redistributable x64
Microsoft Visual C++ 2015 Redistributable x86
The (thread-safe) preview of the PHP 7 MSSQL drivers: https://github.com/Azure/msphpsql
I have uncommented/added the following lines of my phpini:
extension=php_pdo_mysql.dll (uncommented)
extension=php_odbc.dll (added)
extension=php_sqlsrv_7_ts.dll (added)
extension=php_pdo_sqlsrv_7_ts.dll (added)
Things to consider:
I can see that the modules are indeed loaded in phpinfo.
I've added the ODBC connection and can see it in System DSN.
I am successfully able to connect via sqlsrv_connect() but not odbc_connect(), which is what all our previous PHP 5.6 scripts are using.
Can't seem to find the answer anywhere else. Any help would be appreciated. Thanks.
I seem to have solved my own issue.
Turns out, the ODBC_CONNECT string uses an explicit DSN name and not a database, apparently...
Previously my ODBC Connect string was $conn = odbc_connect('DB',$DBUSER, $DBPASS)
and my ODBC Data Source was "SERVERNAME"
Once I changed the ODBC Data Source name to match the DB name, it worked.
I have installed the Pervasive v10 linux 32 bit ODBC client (64 bit is not available) on Centos 6.2 64 bit. I can successfully use isql to connect to a remote data source. However, when attempting to connect via PHP with:
$connect = odbc_connect("demodata", "", "");
I get the same error isql gave me before I got my environment variables correct.
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib '/usr/local/psql/lib/odbcci.so' : file not found, SQL state 01000 in SQLConnect in /var/www/html/pst.php on line 2
I've tried adding the env variables to /etc/sysconfig/httpd:
export PVSW_ROOT=/usr/local/psql
export PATH=$PVSW_ROOT/bin:/bin:/usr/bin
export LD_LIBRARY_PATH=$PVSW_ROOT/lib:$PVSW_ROOT/lib64:$PVSW_ROOT/bin:/usr/lib
export MANPATH=$PVSW_ROOT/man:$MANPATH
export BREQ=$PVSW_ROOT/lib
export LD_BIND_NOW=1
I've added apache to the pvsw group
/usr/bin/gpasswd -a apache pvsw
My guess is that Apache and PHP are running as a 64 bit process and can't load the 32 bit ODBC drivers. I ran a quick install of CentOS 6.2 x64 and installed the default Apache and PHP and saw that it was a 64 bit version. In a phpinfo page, I see "2.6.32-220.el6.x86_64" in the System portion.