Windows 8.1 PHP PDO connection issues again - php

This is the common error often reported in questions:
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Please assume correctly that I've been reading posts for ... 'days'!
I've done all the following:
1) Uncommented: extension=php_pdo_odbc.dll in php.ini
2) Set-up a system DSN in SysWOW64\odbcad32.exe
3) Checked that odbcjt32.dll is present in SysWOW64
My standard (latest PHP) code:
if (!file_exists($dbName)) {die("Could not find database file.");}
try {
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=$dbq;Uid=$user;Pwd=$password");
}
catch (PDOException $e)
{
echo $e->getMessage();
}
There is no file_exists error (so addressing isn't the issue)
The .mdb is mine (so I know the correct Uid/Pwd)
The .mdb is in the same inetpub folder as the .php file calling it (so not permissions)
In windows powershell, I've run: Get-OdbcDsn which correctly shows the rich1 system DSN:
Name : rich1
DsnType : System
Platform : 32-bit
DriverName : Microsoft Access Driver (*.mdb)
Attribute : {DBQ, DriverId, ImplicitCommitSync, Threads...}
Still the same error :-( so I'm dead ended.
Does anyone know of any more 'Get-OdbcDsn' type routines that will help diagnose what's going on? Or any kind of new tack that leads me away from this dead end?

Related

ADODB.ORG - Database Abstraction Layer for PHP to MS Access DB

Trying to get it to connect in this environment:
Windows 7 Pro - 64bit
MS Access 2010 - 32bit (Tried both ACCDB and MDB versions)
ADODB abstraction package, Version 5.20.9
This is the test code:
include("C:\php\adodb5\adodb.inc.php"); // includes the adodb library
$db = NewADOConnection("access"); // A new connection
$db->Connect("", "", "", "D:\...\PhpPlay.accdb");
I've tried all kinds of variations for host, user and password params in the $db-> connect line, but no success. (The first two lines execute without error.) Here's the error message for line 3:
PHP 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 C:\php\adodb5\drivers\adodb-odbc.inc.php on line 66
So I'm grasping at straws now. I'm concerned about the mixed 32/64 bit settings, but don't want to do something drastic unless someone can confirm that this is a problem.
Thank you for any ideas you might be able to provide!
Third party modules are not needed. Simply use PHP's PDO class and the already installed MS Access ODBC driver:
DSN Version
$database="D:\...\PhpPlay.accdb";
$db = new PDO("odbc:DSN=MS Access Database;DBq=$database;");
Driver Version
$database="D:\...\PhpPlay.accdb";
$db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBq=$database;");

PHP PDO ODBC MSSQL connection

I've installed PHP on IIS7 following the official PHP documentation and it succeed. I can run PHP files and my site is OK.
But I can't connect to my database on MSSQL with PDO and ODBC driver. I've set my php.ini carefuly and I think all is good. Morever I also think ODBC is native on Windows and PDO is included in latest PHP builds (mine is 5.5.36).
So here's my connection code :
define("UID", 'uid');
define("PWD", 'pwd');
define("DSN", 'odbc:decheterie');
// where 'decheterie' is the dataSource set in the ODBC Connection Manager
try {
$pdo = new PDO(DSN, UID, PWD);
} catch (PDOException $e) {
die("Error! ".$e->getMessage());
}
The error I get is :
Error! Could not find driver
If I run a php -m I can see that PDO and ODBC modules are correctly loaded.
But a PDO::getAvailableDrivers() returns an empty array and it can be verified within the phpinfo() which displays 'no value' in the 'PDO drivers' section.
I've read a lot of posts and articles and each time a response is valided as 'problem solving' it's already good in my config.
If someone can help it will be blessed ;)
Solved!
The answer is in the above comments. You need to DL the php_pdo_sqlsrv_*.dll
in your PHP /ext folder and references it as an extension in your php.ini
The '*' is for the PHP version everything is well described in the
MSDN doc here
Thanks

Informix PDO connection : Error SQLSTATE=HY000, SQLDriverConnect: -329 sqlerrm(systables)

it has been days (weeks ?) since I try to connect to an Informix SQL database with PHP but I can't make it work.
I'm stuck with this error :
SQLSTATE=HY000, SQLDriverConnect: -329 [Random characters, ex :`�%]
sqlerrm(systables)
I can make the link with Windows ODBC utility http://i.stack.imgur.com/1ChAL.png
But impossible on PHP.
I installed the informix drivers and the informix dll extension for php and run it like this:
putenv("INFORMIXDIR=C:\\informix");
try {
$db = new PDO("informix:host=iat-----; service=sqlexec; database=sige---; server=iat-----; protocol=sesoctcp;", "if----", "pass---");
} catch (Exception $e) {
echo('Erreur : ' . $e->getMessage() . '<br>');
}
Thank you for your kind help.
Error message -329 is:
Database not found or no system permission
It means that despite your best efforts, something is astray with the environment. Either you've misspelled the database name or the server name, or the database is not set up to allow the user access to the database, or something along those lines.
Much more than that, I can't help you with. You're on Windows, and I'm not. You can look at the SETNET32 settings, but the fact that you can connect via the Windows ODBC utility suggests that most of what you need should be OK.
To fix this, you must restart the services for apache and php. If you are in linux, you can use the command "/etc/init.d/httpd restart"
This will fix the following error message:
Ocurrió un error ConexionPDOSQLSTATE=HY000, SQLDriverConnect: -11005 [Informix][Informix ODBC Driver]Unspecified System Error...

Connect sqlite and php using netbeans

UPDATED
My latest code as follows:
$file ="sqlite:C:\New folder\\test.db";
echo $file;
$handle = new PDO($file) or die("Could not open database");
Error
sqlite:C:\New folder est.db
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php:20 Stack trace: #0 C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php(20): PDO->__construct('sqlite:C:\New f...') #1 {main} thrown in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php on line 20
I'm trying to use PDO driver however the error keep prompting me saying cant find the driver when it's in my extension php folder. I'm at my wits now.
I'm using SQLITE version 3 and PHP version 5.4.3.
I already placed the database file inside my r/w folder but it Fatal error: Call to undefined function sqlite_open(). I already researched on the web for alot of sources but the my directory path still returns some strange error (Sorry if i'm too noob, first time learning).
My code as follows:
$db ="C:\New folder\test.db";
Test to print my directory path of the database.
echo $db;
$handle = sqlite_open($db); //or die("Could not open database");
Debug result
C:\New folder est.db
Fatal error: Call to undefined function sqlite_open() in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php on line 18 which is "$handle = sqlite_open($db); //or die("Could not open database");"
Kindly advise where did I do wrong? The path I specified was correct but when I print out, it shows wrong path.
Thanks
one problem you have is that you are escaping (inadvertently) some of your path characters.
As your var_dump shows.
C:\New folder est.db
change your $db variable definition to
$db ="C:\New folder\\test.db";
or just put path in single quotes so PHP won't try and parse the string
$db ='C:\New folder\test.db';
and believe it or not in most cases unix paths will work:
$db ="C:/New folder/test.db";
as for the remainder of your problem, you need to make sure you have sqlite 2 enabled. View your php info and check to see if you a section like:
SQLite
SQLite support enabled
PECL Module version 2.0-dev $Id: sqlite.c 306939 2011-01-01 02:19:59Z felipe $
SQLite Library 2.8.17
SQLite Encoding iso8859
if not, in your php.ini make sure the line
extension=php_sqlite.dll
is uncommented and present (and the .dll exists in your extension folder).
However most people will recommend that you use the PDO driver for sqlite (and for any other database) as it will provide a more consistent paradigm across the different databases (you can use the same code with most databases).
[edit]
I found some comments in the php manual that may shed some light on your issues.
It seems that the directory that contains your sqlite database must be
writeable by the web server. Making just the file writeable won't
work.
and
Don't forget "extension=php_pdo_sqlite.dll" has to be enabled in
php.ini (if you use xampp is will be disabled by default) .

How can I correct this error: Data source name not found and no default driver specified

I have a website that runs in Windows server, and it works perfectly fine. I tried to make a copy in my localhost but I get the 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 in C:\xampp\htdocs\tdms\webfolders\secured\db_fns.php on line 29
Could not connect to database server
line 29 contains:
function fgsdb_connect()
{
$a=array();
$retvar=0;
$result = odbc_connect('FGS','tdms','tdms358',SQL_CUR_USE_ODBC); //---->line 29
if (!$result) // cannot establish connection to database
throw new Exception('Could not connect to database server');
else // connection to database has been established
return $result;
}
I am really new to odbc. the website is written in php and the database that i use in mySQL. though i figured that the database that it is trying to connect is a microsoft access MDE file. (i checked in the site in windows server.) What should i do? im sorry but i am really
It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.
Go to control panel -> administrative tools --> select data sources(ODBC) --> then right click on that file --> go to properties --> in the shortcut tab -> change the path from
%windir%\System32\odbcad32.exe
to
%windir%\SysWOW64\odbcad32.exe
and make your connection. the driver for MS Access will work fine now.
If it doesnt work, try to connect to the ODBC with a sentence like this:
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\YourFolder\YourFile.mdb",'Youruser', 'YourPassword');
The last 2 leave then just the the '' if you dont have any user or password
I was getting the same error on PHP 7.0.8 64bit while trying to connect to an Access .mdb.
I had to do two things:
Install the 64bit version of "Microsoft Access Database Engine 2010 Redistributable" (even with Access 2016 installed I was getting your error). You can download the driver from:
https://www.microsoft.com/en-us/download/details.aspx?id=13255
Then, if you go to the ODBC Data Source Administrator, you should notice the 64bit version.
Change the driver string to:
Driver={Microsoft Access Driver (*.mdb, *.accdb)}
Hope it helps other people.

Categories