ODBC error in php? - php

Hi I was wondering what the following error means and why am I getting it?
[unixODBC][Driver Manager]Data source name not found, and no default driver specified
My arguements for odbc_conntect() - "Driver={SQL Server Native Client 10.0};Server=tcp:database.windows.net;Database=someDB;Encrypt=yes;", 'user#database', 'passwd'

you are running this prog on UNIX and the string is windows based

The reason why it was not working is that I did not have the correct driver installed or unixODBC with a dsn setup.

Related

How to connect to SQL Anywhere database from linux?

I want to access to a SQL Anywhere database which is on another server.
I can do it easily from Windows, but I need to do it from Debian now.
All of this in php.
Windows side :
I have installed SQL anywhere driver from https://archive.sap.com/documents/docs/DOC-35857, and connect with odbc:Driver={SQL Anywhere 16};Server=serveur-02;Port=2638;Database=excalib;Uid=username;Pwd=pwd;
Ok, it works.
Debian side :
I am on Debian 9 with php 7.0.
UnixODBC is already installed and works with some others connections.
FreeTDS is installed too.
So I have make a link in odbcinst.ini :
[SQLAnywhere16]
Description = SQLAnywhere driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
And in odbc.ini :
[Excalibur]
Description = Excalibur
Driver = SQLAnywhere16
Server = [ip]
Port = 2638
Name = excalib
User = user
Password = password
With command
isql -v Excalibur
I got
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[08004][unixODBC][FreeTDS][SQL Server]Erreur SQL Anywhere -83 : La base de
donn▒es sp▒cifi▒e est introuvable
[ISQL]ERROR: Could not SQLConnect
As I understand, it reaches server, but don't find my database. Ok, it's encouraging. Maybe a typo mistake, but I can't find documentation which can tell me, maybe someone has a hint ?
Next step is to do it with php.
odbc:Driver={SQLAnywhere16};Server=[ip];Port=2638;Database=excalib;Uid=user;Pwd=pwd
And... it does nothing. I got nothing from my server (ERR_EMPTY_RESPONSE)
There's nothing in apache's log.
If I do a typo mistake on purpose on the driver path, it sends a correct error
Fatal error: Uncaught PDOException: SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib '/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so1' : file not found in /var/www/html/test.php:24 Stack trace: #0 /var/www/html/test.php(24): PDO->__construct('odbc:Driver={SQ...') #1 {main} thrown in /var/www/html/test.php on line 24
And... I'm lost. Someone can help me ? Or maybe has another solution to connect to SQLAnywhere database ?
Thank you.
Edit [thank to Nitrex] :
When I try to connect via php, tcpdump doesn't capture anything, so I think the problem come from Debian side.

PHP 64 bit - Teradata ODBC driver failure - system error 126 'specified module cannot be found' -

I have installed PHP 5.6.30 64 bit on Windows Server 2012 along with Teradata ODBC driver.
Whenever I test the PHP connection I receive an error
Warning: odbc_connect(): SQL error: Specified driver could not be loaded due to system error 126: The specified module could not be found. (Teradata, C:\Program Files\Teradata\Client\15.00\ODBC Driver for Teradata nt-x8664\Lib\tdata32.dll)., SQL state IM003 in SQLConnect
EDIT: C:\Program Files\Teradata\Client\15.00\ODBC Driver for Teradata nt-x8664\Lib\tdata32.dll does definitely exist on that specific path. Also, using tdxodbc.exe to test the ODBC connection works normally using tdata32.dll, so it appears to be some issue with PHP.
I have installed Teradata ODBC via GSS > ICU > ODBC from the Utilities package based on a related thread however still experiencing the same error. I can make a successful 32-bit ODBC connection via SQL assistant. I have tried a DSN / DSN-less ODBC connection via PHP but same error occurs.
I have been unable to find any clear indication of what the issue is - any idea?

[unixODBC][Driver Manager]Data source name not found, and no default driver specified

I'm updating a application to stop using 'mssql_connect' to use PDO with ODBC for PHP 7.
Locally, I'm using XAMPP on Windows 8 and my application works fine. However, when I upload it to the Ubuntu server (Locaweb hosting, in Brazil) it returns the following error:
PDOException: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified in /public_html/user/log-connections/connection.php:28 Stack trace: #0 /public_html/user/log-connections/connection.php(28): PDO->__construct('odbc:Driver={SQ...') #1 /public_html/user/log-connections/login.php(2): require_once('/public_html/user...') #2 {main}
The line causing the error (connection.php:28) is this one:
$pdo = new PDO("odbc:Driver={SQL Server}; Server={$servername}; Database={$dbname};", $username, $password);
I already tried using other driver names, such as "SQL Server Native Client", "FreeTDS", etc. But all returns the same error. Another thing is that the SQL Server isn't on the same server.
The solutions that I found on my research was telling me change the odbc.ini file and other files. But, I don't have access to those file on the server. Besides, on my local, I didn't change none of those files, just extended the modules to activate PDO and ODBC on the PHP.
Also, I already checked the phpInfo and the PDO and ODBC are enabled with "PDO Driver for ODBC (unixODBC)".
Anyone have experienced this kind of problem?

MS Access DB in php 64bit SQL state IM002 error

I'm trying to fetch data from access db in php. Code works fine for 32 bit php( I've tested in php version>5), but code generates error for 64bit php wamp.
Error Message: Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in
What I've tried : How can I correct this error: Data source name not found and no default driver specified
Code :
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$db", "","");
$tabs = odbc_tables($connection);
Is there any solution or I've to install 32 bit version?
Microsoft Access Driver (*.mdb)
refers to the older Access "Jet" driver which is installed as part of Windows itself but is only available to 32-bit applications. (There is no 64-bit version of Jet.)
You could download and install the 64-bit version of the newer Access Database Engine (a.k.a. "ACE", available here) and then use
Microsoft Access Driver (*.mdb, *.accdb)
as the driver name. (Assuming that the WAMP server does not already have a copy of Access 2007 or later installed on it.)

PHP Connection to MS SQLServer 2008 from Linux via PDO

I need to connect to a MS SQLServer 2008 service from PHP on Ubuntu, and I would like to do so using PDO. I believe I have installed all the prerequisite libraries, and I am indeed able to connect using tsql on the command line and using mssql_connect() in code. I can't figure out what the proper DSN is, or if there are any additional PDO-specific configuration steps I am missing.
I am using the following DSN (where $db* variables are populated with their appropriate values):
odbc:Driver=FreeTDS;SERVER=$dbServer;DATABASE=$dbSchema;UID=$dbUser;PWD=$dbPasswd"
My error message is:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /home/timothy/test.php:4
Stack trace:
#0 /home/timothy/test.php(4): PDO->__construct('odbc:Driver=Fre...')
#1 {main}
thrown in /home/timothy/test.php on line 4
What additional configuration steps have I over looked?
Thanks in advance.
You shouldn't need any additional configuration if you can connect with tsql and the mssql extension. You probably just don't have the correct dsn. This documentation should help. Try new PDO("dblib:host=xx.xx.xx.xx;dbname=mydatabase", "username", "password");

Categories