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.
Related
I am trying to connect IBM-DB2 database using odbc_connect. Below is the sample script to test the connection for IBM-DB2 Database
$conn = odbc_connect("DRIVER={IBM DB2};SERVER=10.100.200.99;DATABASE=TESTDB;","john","doe");
if (!($conn)) {
echo "<p>Connection to DB via ODBC failed: ";
echo odbc_errormsg ($conn );
echo "</p>\n";
}
When executed in Windows it throws below exception
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified, SQL state
IM002
When executed in Linux it throws below exception
Warning: odbc_connect(): SQL error: [unixODBC][IBM][CLI Driver]
SQL30081N A communication error has been detected. Communication
protocol being used: "TCP/IP". Communication API being used:
"SOCKETS". Location where the error was detected: "127.0.0.1"
How could I resolve above error and connect to IBM-DB2 database?
odbc_connect documentation
If you are using only a DSN in the connection string then the odbc.ini (or equivalent) needs to specify the other details (hostname/ip-address, port-number, database name) etc.
If you are not using a DSN in the connection string, then that connection-string must include the hostname/ip-address of the Db2-server, along with the port-number and database name and any other attributes you need.
Your symptom on Linux is most likely due to simple issues like incorrect or incomplete connection string or DSN definition, or Db2-instance not started, or Db2-instance not listening on specified port-number on specified IP-address.
PHP works fine with Db2 on Windows/Unix etc.
Consider using pdo_ibm or ibm_db2 extensions to PHP to have better integration between PHP and Db2 (although these are not related to your symptoms).
I'm new to the PHP framework Laravel and I wanted to connect it with my database. What I have is:
sqlsrv as default database connection
add sqlsrv configuration
Change the .env file
Added the PHP driver to connect with SQL Server
But nothing is working :( The error I get is:
SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server (2)
Anyone who knows how to solve this?
I tried MySQL and that connection worked btw ;)
In the SQL Server Configuration Manager > SQL Server Network Configuration > TCP/IP > Properties> TCP Port check if it is set to 1433. Then restart services.
If MySQL is working and not mssql, I am assuming PHP_dblib module has not been installed.
The bellow code will display installed modules.
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(..)
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 )
I cannot connect to a SQL server database from my Mac. Here's my PHP code:
$db = &ADONewConnection('odbc_mssql');
$db->debug = true;
$myDSN="DRIVER={SQL Server Native Client 10.0};SERVER=XXX.XXX.XXX.XX;PORT=1433;UID=XXXX;PWD=XXXXX;DATABASE=XXXXX;";
$db->Connect($myDSN);
I've tried a whole bunch of different drivers (FreeTDS, SQL SERVER, SQL Server Native Client etc.) but I keep getting this error:
SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002
FYI, I've installed php5-mssql, freetds and unixODBC.
Thanks in advance for your help.
The error is trying to tell you that you do not have a "DRIVER={SQL Server Native Client 10.0};" on your machine.
This comes as no surprise since the SQL Server Native Client is only available on Windows.
What you need is a third party ODBC driver (or the like) such as the OpenLink Single-tier ODBC Driver for SQL Server