how to find ODBC driver name? - php

I am using PHP 5.5 and ODBC installed and active but still I have that error I couldn't connect the server. I Guess I need odbc driver name.
$conn = "DRIVER={SQL Server};SERVER=$server;DATABASE=$db";
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in

You can be using PDO to connect. If you are on windows:
$this->stmt = new PDO ("sqlsrv:server=$server;Database=$database;",$user,$pass);
On Linux:
$this->stmt = new PDO ("dblib:host=$server;dbname=$database;charset=UTF-8;",$user,$pass);

Related

Error with SQL_ODBC_CURSORS during initialization PDO

When I try to initialize a new instance of the PDO class using the odbc driver, I get the following error.
Error: PDO Error: SQLSTATE[HY024] SQLSetConnectAttr SQL_ODBC_CURSORS: 0 [unixODBC][Driver Manager]Invalid attribute value
Why can I get this error?
I tried to find similar problems, but I did not find anything similar. Partially similar problems were solved by the advice to install Microsoft ODBC Driver 17 for SQL Server, I have it
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.1.1
UsageCount=1
but the problem is still there

PHP ODBC - connect to local .mdb database

I've installed the php5-odbc library.
Trying to connect to a .mdb file but keep getting error Data source name not found, and no default driver specified.
Code:
$dbName = "../../../var/Import/PartsPlaceDB.mdb";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");
Outputs:
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 [...]
PDO Drivers:
foreach(PDO::getAvailableDrivers() as $driver)
{
echo $driver.'<br />';
}
Output:
mysql
odbc
sqlite
The problem is recurrent with 64-bit version. It looks like your code only work on Windows 32-bit.
To solve the problem, you might install this tool: Microsoft Access Database Engine 2010 Redistributable. I had the same problem for months but this tool solved mine.
I guess you're doing the location wrong?
Instead of this
$dbName = "../../../var/Import/PartsPlaceDB.mdb";
Why not do it like this
$dbName = "..\..\..\var\Import\PartsPlaceDB.mdb";

php_connect to odbc source produces TNS:could not resolve service name error after Xampp reinstall

I just updated my Windows Xampp install to get the latest PHP version and after the reinstall my web app is giving me the following error when trying to connect to an Oracle data source via the Microsoft ODBC driver for Oracle.
Warning: odbc_connect(): SQL error: [Microsoft][ODBC driver for
Oracle][Oracle]ORA-12154: TNS:could not resolve service name, SQL
state 08001 in SQLConnect in C:\xampp\htdocs\webapp\connections\db.php
on line 34
The code I'm using for this is;
$dsn = 'dsnname';
$user = 'username';
$pass = 'password';
$conn = odbc_connect($dsn, $user, $pass, SQL_CUR_USE_ODBC);
This was working fine before I did the Xampp update and now suddenly it's not working. I think I had this problem once before but I'm convinced it was solved by adding the SQL_CUR_USE_ODBC cursor.
Anyone got any ideas on what could be wrong?

Connect PHP to UniVerse ODBC DSN

I have what seems a simple question, but I just cant get php to connect to my ODBC DSN.
I have a webserver with an ODBC DSN configured properly, I can test the connection and it works just fine.
I am now trying to connect PHP to this DSN.
MYDSNNAME is using the driver: UniVerse 64-Bit ODBC Driver.
Here is my php code:
$conn=odbc_connect('MYDSNNAME','username','password',SQL_CUR_USE_ODBC);
if (!$conn)
{
exit("Connection Failed: " . $conn);
}
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}
dbc_close($conn);
I am getting the following error:
Message: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect
I have tried using the 64bit ODBC administrator and that did not work. Any suggestions would be great.
Thanks
I was able to circumvent the error I was getting by using the 32bit version of the driver within my ODBC Administrator and I am now connecting just fine.
It gets a little tricky with 32/64bit versions of the odbc administrator.

ODBC connectivity in PHP

I have created an ODBC DSN (icamexamdata) for a MS Access DB. Mine is Win 7 OS. I used the following code to connect to the DSN
$conn=odbc_connect('icamexamdata','','');
I couldn't connect and I get the following error.
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect
Can anybody help?

Categories