I am trying to connect php with ms sql server in lamp environment.
$con = new PDO('odbc:Driver=FreeTDS; Server=HOST; Database=TWO; UID=sa; PWD=123456789;');
I go through like 100+ suggestion.Nothing works ,
all i get is a BIG and SAME Error SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Can anyone please give a working example, they might tried already.
If you have freeTDS installed try one of the following connection string it works for me:
$db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password");
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");//if using dblib
Related
I tried connect IBM database through PDO using below code. But, it is not working
try {
$db = new PDO("odbc:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=BLUDB;HOSTNAME=hostname;PORT=50000;PROTOCOL=TCPIP;", "username", "password");
echo "<pre>";
print_r($db);
exit;
} catch (PDOException $e) {
echo $e->getMessage();
}
I got below error for the same
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I have also added below code in php.ini file
extension=php_pdo.dll
extension=php_pdo_ibm.dll
extension=php_ibm_db2.dll
Could anyone suggest me, how I can connect with IBM database?
The DSN prefix for DB2 databases is ibm:, not odbc:. Try changing that.
Here is the example connection string given in the documentation:
$db = new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=testdb;" .
"HOSTNAME=11.22.33.444;PORT=56789;PROTOCOL=TCPIP;", "testuser", "tespass");
there is different driver name for some computer, this is the list of driver you can try:
DRIVER={iSeries Access ODBC Driver};
DRIVER={IBM i Access ODBC Driver};
and try to use System instead of HOSTNAME
DRIVER={iSeries Access ODBC Driver};DATABASE=BLUDB;System=hostname;PORT=50000;PROTOCOL=TCPIP;
oh, and I'm using DRIVER={IBM i Access ODBC Driver};
I'm trying to connect to a MSSQL database using PDO with odbc. I'm aware that there's a package SqlSrv (but for some reason that package (.dll) won't load properly). So I found some documentation arguing it's also possible with PDO. In my PHP.ini I've enabled the extension php_pdo_odbc.dll and it loads fine.
My connection string looks like this:
$conn = new PDO(
'odbc:
Driver=SQL Server;
Server=MyServer\MyInstance;
Database=MyDatabaseName;
Trusted Connection=Yes;',
'MyWindowsUserName',
'MyWindowsPassword'
);
I've tried various properties (for example by prepending the domain to the username, switching with the authentication options User Id, UID, Password, PWD and Trusted Connection) but I keep getting the message
SQLSTATE[28000] SQLDriverConnect: 18456 [Microsoft][ODBC SQL Server
Driver][SQL Server]Login failed for user 'MyWindowsUserName'.
Any suggestions on how to connect to the database with my Windows Account? (that's the only way for me to connect to the database)
Try removing the username & password
$conn = new PDO(
'odbc:
Driver=SQL Server;
Server=MyServer\MyInstance;
Database=MyDatabaseName;
Trusted Connection=Yes;'
);
I have authenticated by Windows with following PHP statement:
This is my code:
$ Conn = new PDO ("odbc: Driver = {SQL Server}; Server=JAMILI-PC\SQLEXPRESS; null; null");
I am using Windows 2008.
I hope it solves your problem.
On my old server I have everything configured for PHP to be able to connect to MSSQL through odbc. I use this simple function to connect to database:
$connid = odbc_connect('ww', 'sa', ODBC_PS);
It works but on the new server it doesn't connect. Can you suggest what does this strange connection string 'ww' means? I use SQL server 2012 now, before I had 2008.
Error I get when trying to connect is:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in(..)
I'm running WAMP 2.5 with PHP 5.5.12. I'm trying to use odbc_connect to connect to a FoxPro database and eventually query for certain records. But then I realized that dbase is no longer maintained which would of allowed me to access the records for dbf databases. So I tried using ODBC with this code:
<?php
$dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\wamp\www\chartnames.dbf;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
$conn = odbc_connect($dsn, "", "");
if (!$conn)
exit("Connection Failed: " .$conn );
//select rows
$rs = odbc_exec($conn, 'SELECT * FROM chartnames');
//display the results
$string = odbc_result_all($rs);
?>
But when I run this code I get an error message:
If you can't read the error is says this:
Warning:odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager]
Driver does not support this function, SQL state IM001 in SQL Connect
I looked up ODBC on php.net I found that only certain databases are supported by the Unified ODBC functions: Adabas D, IBM DB2, iODBC, Solid, and Sybase SQL Anywhere.
Is it possible to connect and query a .dbf FoxPro table with the new versions of PHP? or
Thank you in advance.
UPDATE:
I know that the ODBC driver is no longer supported so they offer OLEDB. I found the OLEDB connection string from here. So I tried replacing the $dsn variable with this connection string: Provider=vfpoledb.1;Data Source=c:\directory\demo.dbc;Collating Sequence=machine but I get the same error as stated above. What gives?
$database='comdb';
$hostname='localhost';
$port=1527;
$user='root';
$password='pass';
$DSN = "DRIVER={IBM DB2 ODBC DRIVER};PROTOCOL=TCPIP;"
. "DATABASE=$database;HOSTNAME=$hostname;PORT=$port;"
. "UID=$user;PWD=$password;";
$dbh = new PDO("odbc:$DSN");
i installed the DB2 ODBC driver and apply php_pdo_odbc.dll on php ext
and still i can't connect to derby error appear after i run the script
Failed to connect: SQLSTATE[08001] SQLDriverConnect: -30082 [IBM][CLI Driver] SQL30082N Security processing failed with reason "17" ("UNSUPPORTED FUNCTION"). SQLSTATE=08001
please let me know if there is alternate way to connect to derby database.
i can access the database using SQuirrel SQL Client but i need to connect it using php.
thanks
I don't believe that the DB2 ODBC driver can connect to the Derby Network Server. However, this question has some ideas you could pursue.