I am using PHP to connect to an MS access .accdb using the following connection
try {
$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb,
*.accdb)};Dbq=C:\\xampp\\htdocs\\seedOnline\\db\\seed12c.accdb;Pwd=");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) { //if connection fails
echo 'Seed Database Connection failed: ' . $e->getMessage();
}
This program works on two different computers with Xampp and Apache in our office, but when copying the entire program to new computers it failswith the following error:
Seed Database Connection failed: SQLSTATE[IM002] SQLDriverConnect:
0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Here is line 34:
foreach ($conn->query($qryUsers) as $qryUsersRow) {
The query $qryUsers is :
$qryUsers = "SELECT * FROM tblPwd";
and the table does exist.
Any particular configuration that I may be missing? All machines are windows 8.1 64 bit.
Related
I am attempting to set up a website on my Windows 10 machine using IIS. I can successfully load a simple php file (using PHP 8.1).
When I attempt a new PDO call to MSAccess I get:
HTTP Error 500.0 - Internal Server Error
C:\php\php-cgi.exe - The FastCGI process exited unexpectedly
My code is
$dbName = $_SERVER["DOCUMENT_ROOT"] . "\\vhs\VHS.accdb";
try {
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$dbName;Uid=admin;");
}
catch (PDOException $e) {
echo $e->getMessage();
}
Nothing gets placed into the php_errors.log.
I have both
extension=pdo_odbc.dll
extension=php_pdo_odbc.dll
in my php.ini file (and both exist in the ext folder).
I have tried the following:
1 - a different MSAccess database (both another .accdb and an old .mdb) ... same error
2 - using the incorrect driver name (for example "Microsoft Blah Driver") ... this results in a PDOException "SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" so I believe I have the driver spelled correctly in my original code
The Microsoft Access Driver (*.mdb, .accdb) name matches the one I see in the 64-bit ODBC administrator. If I instead use Microsoft Access Driver (.mdb) which appears in the 32-bit administrator I get the 'Data source name not found' error as well.
Does anyone have any suggestions for things to check / try?
I am trying to connect the Microsoft access database using PDO with odbc. I have mounted the files on network drive and I am trying to access them, but I am getting the following error:
PDOException' with message 'SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb)'': file not found'.
Here is my code:
$dbName = "/info/new.mdb";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$database = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq= $dbName;Uid=admin");
First, make sure the odbc extension is activated in the php.ini file. Just remove the ; to enable it.
;extension=php_pdo_odbc.dll
Then for connection, please use the exact file location with proper convention (it should be using backslash). The example is below.
try {
$file_location = "C:\Users\PC1\Desktop\your_database.mdb";
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$file_location;Uid=Admin");
//Do your program stuffs here
$dbh = null;
} catch (PDOException $e){
echo $e->getMessage();
}
I just installed the Zend Server on my system and I'm trying to test my database connections. I prefer using PDO to connect my databases.
MySQL connection works very well, but when I'm trying to connect MS SQL server I got an error.
Connection to MSSQL Server failed: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified
This is the code that I'm trying to run
try {
$pdo = new PDO('odbc:host=ip-addr; dbname=my-database', 'user', 'password');
echo "Successfully connected to MSSQL Server";
} catch (PDOException $e) {
echo "Connection to MSSQL Server failed: " . $e->getMessage();
}
I have successfully enabled odbc and pdo_odbc in the configuration panel. I'm running this on macOS Sierra 10.12.
Thanks in advance.
I found this tutorial, and it brought me to succeed. It's written for Linux, but I just installed Homebrew and followed the tutorial a bit adapting.
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";
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.