I'm running PHP 5.2.4 with ibm_db2 v1.8.0 on Ubuntu 8.04.1 Server. I am trying to hit an IBM iSeries running OS/400 v5R3 but I'm not sure at all how to actually connect without a DSN. I've looked at http://www.connectionstrings.com/ but none of the DB2 or AS/400 connection strings seem to work. All I end up with is:
[IBM][CLI Driver] SQL1013N The database alias name or database name "" could not be found. SQLSTATE=42705 SQLCODE=-1013
Here is my current DSN string:
DRIVER={iSeries Access ODBC Driver};SYSTEM=192.168.0.20;Uid=user;Pwd=password
I've also tried the 'IBM DB2 ODBC DRIVER' but get the same error as the string above.
Here is what I use within the .NET environment:
Provider=IBMDA400.DataSource.1;Data Source=xxx.xxx.xxx.xxx;Password=xxxxxxxxxx;User ID=xxxxxxxxxx;Initial Catalog=SERVERNAME
You might be missing the "Initial Catalog".
As it turns out, I had to use ODBC as there wasn't an easy way to access DBU from PHP without having to set up DB2-C and pipe everything through there.
Related
I am trying to connect to a Firebird database using PHP.
This is the simple code that I use to connect to it.
$user = "******";
$password = "******";
$ODBCConnection = odbc_connect("DRIVER={Firebird/InterBase(r) driver};Database=******;Server=******;Port=******", $user, $password);
I have installed the ODBC driver for Firebird from this webpage https://www.firebirdsql.org/en/odbc-driver/. I've managed to add the correct (I believe) string to the DRIVER inside the ODBC Conection, but now I encounter this error:
Warning: odbc_connect(): SQL error: [ODBC Firebird Driver]Unable to connect to data source: library 'gds32.dll' failed to load, SQL state 08004 in SQLConnect
I am running an Apache server using XAMPP on localhost. Everything I wrote is in the index.php file, just trying to connect to the database.
Any help would be greatly appreciated.
This error occurs when you do not have the Firebird client library (fbclient.dll, or gds32.dll which is tried as a fallback) installed on your system (or you have it installed, but it has the wrong bitness).
To install the Firebird client library, use a Firebird server installer of the right bitness* (eg Firebird 3 Windows 64-bit from https://www.firebirdsql.org/en/firebird-3-0/), and install the Client components.
That said, if you're using PHP, it might make sense to use the Firebird PHP driver instead (though this will still need fbclient.dll to be installed).
*: right bitness: If you use a 32-bit PHP, you need the 32-bit client library, if 64-bit, then the 64-bit client library.
In PHP scripts, it looks like this is how you connect to an odbc database:
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
The problem I'm having is that I don't know what to use for "Driver=". What I put in there is what was provided for another script I saw. In my script, all I do is try to connect using this line, but I get the following error:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /srv/www/htdocs/site/test.php on line 8
From what I can tell, it looks like the driver I specified is incorrect. The database I am trying to connect to is an MSSQL database, and I only plan to query for information from it. Is there a way to list the database drivers I have available on my system? I've never had to install/configure any drivers like this before (I've never done anything like this; all php work I've done in the past has been with MySQL). Also, I don't want to compile other software onto my system (if possible); I would prefer to install all packages from repos.
You should have a file called odbcinst.ini (probably in /etc or /usr/local/etc but you can locate it with the command odbcinst -j). This file defines your ODBC drivers. Each driver is named within the [] in each section.
You might find Linux ODBC useful as it contains a thorough explanation of unixODBC, how it works and how to define data sources.
The question was how to find the list of ODBC drivers available. In the command line run:
odbcinst -q -d
This will list the drivers if you don't know already.
I'm trying to connect to a Sybase database with PHP5. I believe I've successfully compiled PHP with PDO_DBLIB, as phpinfo() lists dblib under PDO drivers, and freetds as the pdo_dblib flavour.
However, when I try to test a connection, I get an error reading:
'PDOException' with message 'could not find driver'
I'm trying to connect to a server on my LAN with this code:
$dbh = new PDO("sybase:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
Any suggestions would be greatly appreciated!
You should use dblib instead of sybase, like this:
$dbh = new PDO("dblib:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
PDO wouldn't work, or at least there is no PDO Sybase support for php. On Windows, you can use ODBC, and PDO_SQLSRV or PDO_ODBC, it might sound weird, but it should work.
Second option and I would recommend it, is to connect directly to Sybase (SqlAnywhere), but you need to install SQL Anywhere PHP Module
If you are using Ubuntu you can put the LD_LIBRARY_PATH inside envvars and it seems to read... still trying to find a way to get it to stick on RHEL based systems... Windows I am not too sure about I would hope you could set a system wide variable under
my computer -> properties -> advanced options
If are using RHEL based systems it might be better to include the:
export LD_LIBRARY_PATH=/path/to/library/ in the httpd restart script (check to see if it loads /etc/sysconfig/httpd and if so add the line in there - now restart apache and you should see some activity.
I have been trying to connect to a ibm db2 database but it seems impposible. The as400 is in a different server than the one running php.
Everytime I do a db2_connect I get the following error:
Fatal error: Call to undefined function db2_connect()
How can I make this function work?
Tip: I've already tried with odbc and it was a lost of time, but I'm open to suggestions on that path as well.
[EDIT]
I finally changed to java... it was impossible with php...
Check your php.ini file and make sure it has the DB2 extension enabled. http://www.php.net/manual/en/install.pecl.php
Try this link:
http://www.theregister.co.uk/2006/08/09/db2_udb_part2/
Deals with:
Installing the PHP DB2 extension,
Creating a connection,
Obtaining a result set
Also gives as an alternative the PDO option.
But as for DB2 on the AS400, am not sure if something still needs to be installed on the
AS400 for this to work?
Anyway, have used the ODBC Client Access with no problems at all. What difficulty did you run into?
I have the issue, to get a PHP script connecting to an Informix DB. I thought installing the Zend-server community edition and in addition the pdo_informix extension. When I run the Zend-server admin in the browser, I see the pdo_informix extension marked as "green". Afterwards I've installed the Informix ClientSDK 3.70 on Ubuntu. I've set the $INFORMIXDIR environment variable into /etc/profile and into the PATH variable to the bin directory. The installation dir was /opt/IBM/informix . When I now try to write code in PHP like
try{
$db = new PDO("informix:host=xx.xx.com;database=xxx;server=xxx_net; protocol=onsoctcp;", databaseuser, databasepassword);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "test";
}catch (PDOException $e){
echo "<br/>Failed: ". $e->getMessage()."<br/>";
}
I've got the following error in the browser:
Failed: SQLSTATE=HY000, SQLDriverConnect: -23101 [Informix]
[Informix ODBC Driver][Informix]Unspecified System Error = -23101.
If I'm trying to connect with the Server Studio on Ubuntu to the Informix DB it works well, but I guess they are using the JDBC driver.
If I go to the bin directory of my Informix clientsdk, there is an application called finderr. If I do a finderr -23101 I get the following output:
./finderr -23101
-23101 Unable to load locale categories.
So i thought that I have to set the DB_LOCALE, CLIENT_LOCALE environment variables... my server is using en_us.819 and my client is using en_us.utf8 .
Being unable to load locale categories normally means that either INFORMIXDIR is not set for the software trying to access the Informix locale data (which is found in $INFORMIXDIR/gls), or that the locale categories are unspecified or mis-specified. These are classically the environment variables CLIENT_LOCALE and DB_LOCALE, which have values such as 'en_us.8859-1' (the default) or 'es_es.utf8' (Spanish in Spain using UTF-8).
I would concentrate on ensuring that the browser has the environment set correctly. It may depend on how you launch it.
There are some other environment variables that could be used - DBLANG, LANG, and the LC_* set of names. However, they are unlikely to be needed if CLIENT_LOCALE and DB_LOCALE are set. With that said, I've recently found that with Informix 4GL (I4GL), some code written with Japanese characters in things like table names would not compile unless DBLANG was set as well as the *LOCALE variables. However, the LC* and LANG variables seemed to have minimal to no effect on the result.
You probably have to set LD_LIBRARY_PATH. I do it with:
export LD_LIBRARY_PATH=$INFORMIXDIR/lib/:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql:
export PATH=$INFORMIXDIR/bin:$INFORMIXDIR/lib:/usr/local/bin:/usr/bin:/bin
If that will not help then you can try with unixODBC. It seems that PHP uses some kind of ODBC. In unixODBC online manuals there is article about connecting to Informix - read it. Use isql (interactive SQL) unixODBC tool to connect to configured ODBC database.
If isql cannot connect to database with the same error then you can use strace to see what library the ODBC driver cannot load.