How to use ODBC to connect with Paradox DB with PHP? - php

I'm currently working on a project: Write a Web Application that is able to make connection to pdx .db file.
This post gave me a little hint, but it was not complete. What I got from it is basically to use ODBC to work with Paradox databases.
But since resources about Paradox DB is very limited, I have not found any manual about how to connect to Paradox with Php & ODBC.
What I have tried:
<?php
$database = "C:/Data/data.db";
$conn = odbc_connect("DRIVER={Microsoft Paradox Driver (*.db )};Database=".$database, '', '');
?>
But then it returned this message:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
If anyone knows how to fix the connection string, please kindly help.
Any suggestions would be greatly appreciated!

Related

Using ADOdb with ODBC and Oracle

I've been given access to an Oracle Server via ODBC and tested the connection using Oracle SQL Developer. These are the connection constants I've set in PHP:
define('APP_DB_HOST', '192.168.1.1');
define('APP_DB_PORT', '1521');
define('APP_DB_USER', 'MyUser');
define('APP_DB_PASS', 'MyPass');
define('APP_DB_SID', 'MyDatabaseSID');
define('APP_DB_SCHEMA', 'MyDatabaseSchema');
With ADOdb/ODBC, I should be able to use the below, so that I don't need to involve a tnsnames.ora entry:enter link description here
$dsn = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST='.APP_DB_HOST.')(PORT='.APP_DB_PORT.'))(CONNECT_DATA=(SERVICE_NAME='.APP_DB_SID.')));User Id='.APP_DB_USER.';Password='.APP_DB_PASS.';';
$db->PConnect($dsn, APP_DB_USER, APP_DB_PASS, APP_DB_SCHEMA);
I get the ADOdb Warning:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in [..]/adodb/drivers/adodb-odbc_oracle.inc.php on line 87
Have others done this before, and if so, how so?
Beyond ADOdb, if anybody has a less complicated method of connecting by ODBC to Oracle with PHP7.4+, please do share.
I would also suggest you to move to the OCI8 native driver if you have a bit of time and not too much refactoring to do.
Your server should already have an Oracle client installed (to make the current TNS and ODBC work), so the only thing to do is to install the OCI8 Oracle DDL PHP extension. Just copy it to php/ext/ and load it in your php.ini
In the meantime, you can test if the following code works:
require_once("include/adodb5/adodb.inc.php"); //depends on your adodb folder
$conn = NewADOConnection("oci8");
$conn->connect(APP_DB_HOST, APP_DB_USER, APP_DB_PASS, APP_DB_SID);
For info, you can check if your system admin has already installed the OCI8 extension by looking for the OCI8 section in the PHPINFO :
If that is an option for you, I would strongly recommend to connect using the native oci8 driver, instead of relying on ODBC. Refer to ADOdb documentation for connection examples.
If you're stuck with ODBC, then I believe you need to adjust your DSN to specify the name of the driver you want to use in the connection string, e.g. Oracle in instantclient_19_6
Driver={OdbcDriverName};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=xxx))(CONNECT_DATA=(SERVICE_NAME=xxx)))
In my opinion it's better to specify the user id and password in the function call, i.e. $db->connect($dsn, $username, $password), but if you must have it in the connection string, you may want to try it with uid=xxx;pwd=xxx instead of User Id=xxx;Password=xxx
As an alternative, you could also create a System DSN in your ODBC configuration, and just refer to it by name, instead of hardcoding the TNS connection string directly in your code.
See also Create a DSN for the function odbc_connect for Oracle.

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;");

pdo dbf files and queries

Good day everyone, i have an application that uses .dbf files to store data and i would like to run some queries on those files. the problem is that i don't know how .. i've spoken with the people from support about it and they told me that i can an ODBC driver or the dedicated one for visual foxpro Ole DB. I found something called dabse in php manual yet on php 5.3 it doesn't support it or i didn't install it right because it didn't work, from what i've read on google seems that it supports until php 5.2 or something like that.
Can you help me figure it how to do it ? i've googled around but couldn't find anything that might help me out.
Edit
$excelFile = realpath('C:\\db\\article.dbf');
$excelDir = dirname($excelFile);
$dsn = "DRIVER={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=C:\\db\\article.dbf;DefaultDir=$excelDir;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
$conn=odbc_connect($dsn,"","");
$sql = "SELECT * FROM articole.dbf";
$result = odbc_exec($conn, $sql);
The Error:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC dBase Driver] External table is not in the expected format., SQL state S1000 in SQLExecDirect in E:\public_html\odbc\index.php on line 7
Do you have SQL Server? You could create a linked server to the DBF files. Check out this link:
Linked Server
See also these links for querying DBase or Foxpro tables with ODBC or OLE DB:
Dbase ODBC
Foxpro OleDB

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.

adodb with sql server odbc connection problem

ADODB Error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I downloaded the odbc driver for PHP. I pasted that driver in the PHP ext directory, then I get the error. Can anybody help me?
A few things that I would try,
Make sure that the extension is included in your php.ini
Make sure that you've extracted the db driver to the right place c:\windows\drivers in some cases!
Have you rebooted? As you'll need to reboot your server to load the driver, I assume you have as you get the error :)
As the comment above states, which driver you are using, it's version, and which database you're connecting to would also be handy to know :)
I assume that you're using PHP5 to connect to MSSQL2005. In which case the driver is really dodgy, or was when I last worked with it. It would maintain a connection about 1/3 tries. What web server are you using? As I recall when we were using IIS to serve the PHP+MSSql we had some configuration to do in the IIS setup.
try:
# config file
$oODBC = new stdClass();
$oODBC->driver = "odbc_mssql";
$oODBC->dns = "Driver={SQL Server};Server=127.0.0.1;Database=yourdatabhase;";
$oODBC->user = "username";
$oODBC->pass = "password";
# connect
$mDB = $oODBC;
$db =& ADONewConnection($mDB->driver); // ex: odbc_mssql
$db->PConnect($mDB->dns, $mDB->user, $mDB->pass);

Categories