1
votes

This is what I have done so far............

In order to connect my website to an informix database, I installed Informix client SDK and entered server and host information through Setnet32 and the connection was working when tested through ConnectTest Demo .

Then through ODBC Data Source Administrator in windows I created User DSN and System DSN and tested the connection too.

Now I have created a connection string that goes like this:

$dbh = new PDO("odbc:Driver={IBM INFORMIX ODBC DRIVER};HOSTNAME=172.56.100.12;PORT=8056;DATABASE=eadmin;PROTOCOL=onsoctcp; UID=prsnl;PWD=prsnl;");

In this case on trying to login ,the error I get is as follows:

PDOException: SQLSTATE[HY000] SQLDriverConnect: -11060 [Informix][Informix ODBC Driver]General error.

I tried another connection string that goes like this :

$dbh = new PDO("Dsn=bnm_info;Driver={IBM INFORMIX ODBC DRIVER};HOSTNAME=172.56.100.12;PORT=8056;DATABASE=eadmin;PROTOCOL=onsoctcp; UID=prsnl;PWD=prsnl;");

In this case the error I get is as follows:

PDOException: invalid data source name 

To make things more clear,the code for accessing database is as follows:

$query = "select decrypt_char(passwd,'" . $_POST['passwd'] . "') from edak_users where userid='" . $_SESSION['username'] . "'";

$tt = $dbh->query($query);

$rs=$tt->fetch(PDO::FETCH_NUM);

Please suggest a solution to get me through as this issue is driving me nuts.

Any help is highly welcome. Thanking in anticipation

3
As far as the problem goes, the query is irrelevant - you're not even getting connected to the database, so the query will never get a chance to be executed. Which is a good thing, since you're vulnerable to SQL injection attacksMarc B
Please suggest how to connect to database through odbckshiteejm

3 Answers

0
votes

Example #1 PDO_INFORMIX DSN example using odbc.ini

The following example shows a PDO_INFORMIX DSN for connecting to an Informix database cataloged as Infdrv33 in odbc.ini:

Php

$db = new PDO("informix:DSN=Infdrv33", "", "");
[ODBC Data Sources]
Infdrv33=INFORMIX 3.3 32-BIT

Odbc.ini

[Infdrv33]
Driver=/opt/informix/csdk_2.81.UC1G2/lib/cli/iclis09b.so
Description=INFORMIX 3.3 32-BIT
Database=common_db
LogonID=testuser
pwd=testpass
Servername=ids_server
DB_LOCALE=en_US.819
OPTIMIZEAUTOCOMMIT=1
ENABLESCROLLABLECURSORS=1

Example #2 PDO_INFORMIX DSN example using a connection string

The following example shows a PDO_INFORMIX DSN for connecting to an Informix database named common_db using the Informix connection string syntax.

$db = new PDO("informix:host=host.domain.com; service=9800;
    database=common_db; server=ids_server; protocol=onsoctcp;
    EnableScrollableCursors=1", "testuser", "tespass");

source

0
votes

Have you tried much simplier connect string:

$dbh = new PDO("DSN=bnm_info;UID=prsnl;PWD=prsnl;");

Also be sure you defined DSN in proper odbcad32.exe if you work on Win64. There is one for 32 bit applications and another for 64 bit applications.

If your ODBC works from odbcad32.exe then it should work with such simple connect string.

0
votes

If you are trying to run this on Windows forget about odbc.ini, On windows that info is stored in the registry.

The reason for the initial -11060 General Error is because you are missing a key parameter in the connection string (SERVER)

Without it (using a DSN-less connection as you did)

D:\Infx\PHP7\test>cat p2.php
<?php
$dbh = new PDO("odbc:Driver={IBM INFORMIX ODBC DRIVER};HOSTNAME=420ito;PORT=9088;DATABASE=sysmaster;PROTOCOL=onsoctcp;UID=informix;PWD=ximrofni;");
try
{
  $query = "select tabname from systables where tabid=99";
  $tt = $dbh->query($query);
  $rs=$tt->fetch(PDO::FETCH_NUM);
  print_r($rs);
}
catch (Exception $e)
{
  echo "*".$e->getMessage()."*";
}
?>


D:\Infx\PHP7\test>php p2.php
PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] SQLDriverConnect: -11060 [Informix][Informix ODBC Driver]General error. in D:\Infx\PHP7\test\p2.php:2
Stack trace:
#0 D:\Infx\PHP7\test\p2.php(2): PDO->__construct('odbc:Driver={IB...')
#1 {main}
  thrown in D:\Infx\PHP7\test\p2.php on line 2

D:\Infx\PHP7\test>grep SERVER p2.php

Now, with the SERVER it connects without errors:

D:\Infx\PHP7\test>grep SERVER p2.php
$dbh = new PDO("odbc:Driver={IBM INFORMIX ODBC DRIVER};SERVER=ids1210;HOSTNAME=420ito;PORT=9088;DATABASE=sysmaster;PROTOCOL=onsoctcp;UID=informix;PWD=ximrofni;");

D:\Infx\PHP7\test>php p2.php
Array
(
    [0] =>  VERSION
)

D:\Infx\PHP7\test>

SERVER should be the name of your Informix server (usually the value of the INFORMIXSERVER environment variable).

If you have already put the Informix server information in the registry (using setnet32) there is no need to specify all the parameters in the ODBC connection string. You can do:

$dbh = new PDO("odbc:Driver={IBM INFORMIX ODBC DRIVER};SERVER=ids1210;DATABASE=sysmaster;UID=informix;PWD=ximrofni;");

the driver will pick the rest of the values from the registry.

Also, as mentioned earlier, if you already created an ODBC DSN, you can just reference that DSN. Like this:

$dbh = new PDO("odbc:DSN=ids1210_32;UID=informix;PWD=ximrofni;");

Just keep in mind that if your PHP (module) is 64-bits you will need to either create a 64-bit ODBC DSN or use "{IBM INFORMIX ODBC DRIVER (64-bit)}" as the driver name in your dsn-less connection string.

The 'DSN-less' option (all parameters including driver name) is useful if you don't want to store anything on the registry but it's really up to you which one to use ;)