I am struggling to connect a remote database IBM DB2 with my PHP application on the local system using xampp.
I am able to connect the db with PgAdmin.
I have added the extensions in the php extension directory and also enabled the php extensions for db2 and odbc both.
I have provided the correct credentials.
This is the error I am getting while connecting.
odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect
, where as when i connect with php Db2 functions it gives the error function not defined. Please help me in resolving this error.
I am unable to figure out what i am doing wrong.
I'm just trying to connect php and ms-access
in administrative tools I can see that there 2 ODBC Drivers 32 and 64 bit so i configured the 32 bit because I can create a New Data Source using the Microsoft access driver. after that I write this code to check if can now connect to my msaccess
$con = odbc_connect("accessdatasource", "root", "" );
if($con){
echo "Connected";
} else {
echo "Failed";
}
and i got an error that says
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect in C:\xampp\htdocs\connect\index.php on line 7
what could be wrong? I don't get the DSN contains an architecture mismatch
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 am trying to connect to a SQL Server database from PHP but I'm having problems with the connection string. Here is a rundown of what I've tried and the effect it has had:
Running PHP 5.3.13, Apache 2.2.22, Windows 7, and SQL Server 2008 R2
I've installed SQL Server Native Client 11.0
I've dropped using MSSQL driver, using the SQLSRV driver instead.
Loaded these extensions in php.ini: extension=php_pdo_sqlsrv_53_ts.dll, extension=php_sqlsrv_53_ts.dll,
extension=php_pdo.dll.
phpinfo() shows these as active:
Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar, sqlsrv
PDO drivers mysql, odbc, sqlite, sqlsrv
sqlsrv support enabled
Connection code is as follows:
$serverName = "[servername]";
$connectionInfo = array( "Database"=>"[databasename]");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
The string is set up to use Windows authentication, which sqlsrv_errors() reports:
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user '[networkname]\[machinename]'
I have also tried this using my network id/pwd, resulting in
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user '[username]'
I do know that the database is up and functional, as I can connect and run queries without problem from the SQL Server client, and from sqlcmd. The SQL Client and the command line work when using my network/machine credentials. The command line client fails when I try with username/password. This would indicate that any PHP connection should use the Windows authentication to connect.
Someone in another thread suggested that changing permissions in a registry entry would work, but this did not help my issue. PHP 5.3 not recognizing Native Client to connect to MS SQL
I also had some success creating a system DSN. The connection test reports success:
Microsoft SQL Server Native Client Version 11.00.2100
Running connectivity tests...
Attempting connection
Connection established
Verifying option settings
INFO: A network alias was found for the DSN server. 'Protocol: DBMSSOCN; Address: [servername]' was used to establish the connection.
Disconnecting from server
TESTS COMPLETED SUCCESSFULLY!
I've searched extensively within stackoverflow.com, and the interwebs in general with no luck. Obviously the db connection is alive using other methods, but what is going wrong in my connection via PHP?
I got this solved by creating a new login using sql server authentication. I hope this helps somebody with similar issues.
SQLSRV uses the absence of a UID (uid==NULL || strlen(uid) ==0) to indicate that it should try set the "trusted connection" flag in the connection string, i.e. connect using the credentials implied by the execution context.
You can't pass a domain login and password (e.g. UID='MYDOMAIN\user') explicitly.
I had a weird compiler version issue with Microsoft's driver for PHP, and solved my connection problem with PHP's ODBC driver:
//$pdo = new PDO("sqlsrv:Server=$hostname;Database=$dbname;", $username, $password); // works with proper driver for PHP.
$pdo = new PDO("odbc:Driver={SQL Server};Server=$hostname;Database=$dbname;", $username, $password); // works with proper driver for ODBC and PHP ODBC.
When I run apache (via xampp) as a standalone server not as a service (on Windows Server 2008)
with the following connection code everything works fine (username and password removed )
$server = "WMS";
$link = odbc_connect($server,'','');
if (!$link) {
die('Something went horribly wrong while connecting to MSSQL');
}else {echo('');}
If however I change apache to run as a service in Windows the connection breaks and I get the following error message
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\Dev\well.php on line 30
Something went wrong while connecting to MSSQL
Please read documentation: http://uk.php.net/manual/en/function.odbc-connect.php
$server = "WMS"; suggests that you have ODBC alias/data source configured with that name. Error message clearly says that data source with such name (WMS) is not found. On Windows 7/Vista/XP/Server you can configure them at "Start -> Administrative Tools -> Data Sources (ODBC)" -- path can be different on older OS. In any case -- look for "Microsoft ODBC Data Source Administrator".
Instead of using alias, I would recommend (the way I always connect) to use full DSN name, e.g.
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$link = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
In this case everything is part of the script and no external dependencies.
BTW -- instead of using ODBC Functions, I would recommend using PDO & driver specially for MS SQL Server: PDO_SQLSRV -- http://uk.php.net/manual/en/ref.pdo-sqlsrv.php (or Microsoft SQL Server Driver for PHP if you prefer old procedural style -- http://uk.php.net/manual/en/book.sqlsrv.php )