Connecting Tech Pros Worldwide Forums | Help | Site Map

db2 and PHP access

Mairhtin O'Feannag
Guest
 
Posts: n/a
#1: Nov 12 '05
Hello,

When I coded a routine to access a db2 database via PHP, as in the
article from IBM, all seems to work, BUT ... I get the following on the
page, and no connect to the database :

Warning: SQL error: [unixODBC][Driver Manager]Data source name not found,
and no default driver specified, SQL state IM002 in SQLConnect in
/var/www/html/db2lib.php on line 8

Connection to database failed.

Warning: odbc_errormsg(): supplied argument is not a valid ODBC-Link
resource in /var/www/html/db2lib.php on line 12 Fatal error: Call to
undefined function: author_form() in /var/www/html/select.php on line 47


The routine, as coded from the IBM page is :


<?php function dbconnect($verbose) {
$dbname = "spirit";
$username = "db2inst1";
$password = "db2inst1";

// odbc_connect returns 0 if the connection attempt fails;
// otherwise it returns a connection ID used by other ODBC functions
$dbconn = odbc_connect($dbname, $username, $password);

if (($verbose == TRUE) && ($dbconn == 0)) {
echo("Connection to database failed.");
$sqlerror = odbc_errormsg($dbconn);
echo($sqlerror);
}

return($dbconn);
}
?>



Can anyone help me?

Mairhtin O'Feannag
mairhtin at techsolutionsgroupllc dot com (yeah, it's a long one!)

Dan Scott
Guest
 
Posts: n/a
#2: Nov 12 '05

re: db2 and PHP access


Mairhtin O'Feannag wrote:[color=blue]
> Hello,
>
> When I coded a routine to access a db2 database via PHP, as in the
> article from IBM, all seems to work, BUT ... I get the following on the
> page, and no connect to the database :
>
> Warning: SQL error: [unixODBC][Driver Manager]Data source name not found,
> and no default driver specified, SQL state IM002 in SQLConnect in
> /var/www/html/db2lib.php on line 8
>
> Connection to database failed.
>
> Warning: odbc_errormsg(): supplied argument is not a valid ODBC-Link
> resource in /var/www/html/db2lib.php on line 12 Fatal error: Call to
> undefined function: author_form() in /var/www/html/select.php on line 47
>
>
> The routine, as coded from the IBM page is :
>
>
> <?php function dbconnect($verbose) {
> $dbname = "spirit";
> $username = "db2inst1";
> $password = "db2inst1";
>
> // odbc_connect returns 0 if the connection attempt fails;
> // otherwise it returns a connection ID used by other ODBC functions
> $dbconn = odbc_connect($dbname, $username, $password);
>
> if (($verbose == TRUE) && ($dbconn == 0)) {
> echo("Connection to database failed.");
> $sqlerror = odbc_errormsg($dbconn);
> echo($sqlerror);
> }
>
> return($dbconn);
> }
> ?>
>
>
>
> Can anyone help me?
>
> Mairhtin O'Feannag
> mairhtin at techsolutionsgroupllc dot com (yeah, it's a long one!)[/color]

Hi:

A couple of questions:

1) Did you compile PHP with IBM DB2 support? If you did, then PHP will
connect to your database using the native DB2 libraries. If not, then
PHP will connect to your database using the ODBC Driver Manager on your
computer. The unixODBC error makes me suspect PHP wasn't compiled with
IBM DB2 support, so...

2) Have you configured the ODBC Driver Manager on your computer to
support connections to your database?
http://publib.boulder.ibm.com/infoce...d/t0006349.htm
has some good information on how to do this generically on UNIX systems;
http://www.ibm.com/support/docview.wss?uid=swg21079056 offers
information specifically about how to set up unixODBC with DB2 Version 8.1.

Hopefully this will help resolve your problems.

Dan

Dan
Dan Scott
Guest
 
Posts: n/a
#3: Nov 12 '05

re: db2 and PHP access


Mairhtin O'Feannag wrote:[color=blue]
> Hello,
>
> When I coded a routine to access a db2 database via PHP, as in the
> article from IBM, all seems to work, BUT ... I get the following on the
> page, and no connect to the database :
>
> Warning: SQL error: [unixODBC][Driver Manager]Data source name not found,
> and no default driver specified, SQL state IM002 in SQLConnect in
> /var/www/html/db2lib.php on line 8
>
> Connection to database failed.
>
> Warning: odbc_errormsg(): supplied argument is not a valid ODBC-Link
> resource in /var/www/html/db2lib.php on line 12 Fatal error: Call to
> undefined function: author_form() in /var/www/html/select.php on line 47
>
>
> The routine, as coded from the IBM page is :
>
>
> <?php function dbconnect($verbose) {
> $dbname = "spirit";
> $username = "db2inst1";
> $password = "db2inst1";
>
> // odbc_connect returns 0 if the connection attempt fails;
> // otherwise it returns a connection ID used by other ODBC functions
> $dbconn = odbc_connect($dbname, $username, $password);
>
> if (($verbose == TRUE) && ($dbconn == 0)) {
> echo("Connection to database failed.");
> $sqlerror = odbc_errormsg($dbconn);
> echo($sqlerror);
> }
>
> return($dbconn);
> }
> ?>
>
>
>
> Can anyone help me?
>
> Mairhtin O'Feannag
> mairhtin at techsolutionsgroupllc dot com (yeah, it's a long one!)[/color]

Hi:

A couple of questions:

1) Did you compile PHP with IBM DB2 support? If you did, then PHP will
connect to your database using the native DB2 libraries. If not, then
PHP will connect to your database using the ODBC Driver Manager on your
computer. The unixODBC error makes me suspect PHP wasn't compiled with
IBM DB2 support, so...

2) Have you configured the ODBC Driver Manager on your computer to
support connections to your database?
http://publib.boulder.ibm.com/infoce...d/t0006349.htm
has some good information on how to do this generically on UNIX systems;
http://www.ibm.com/support/docview.wss?uid=swg21079056 offers
information specifically about how to set up unixODBC with DB2 Version 8.1.

Hopefully this will help resolve your problems.

Dan

Dan
Closed Thread