...

View Full Version : db2_connect



tdavis
03-25-2009, 05:47 PM
I am trying to test my connection to my i5/OS system. Here is my test script. What am I doing wrong? It always says "connection failed"...

<?php
//Turn on display_errors
ini_set('display_errors','1');
// Display ALL errors including notices
error_reporting (E_ALL);
?>

<?php
$user = 'myuser';
$password = 'mypass';
$hostname = 'myhost';
$conn = db2_connect($hostname,$user,$password);
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
echo "<br>$conn";
}
?>

abduraooft
03-25-2009, 05:53 PM
Use the db2_conn_errormsg() (http://php.net/manual/en/function.db2-conn-errormsg.php) and analyse the error message.
PS:Edit your post to remove the connection parameters, if they are real.

tdavis
03-25-2009, 05:56 PM
So now I see this message:

Connection failed.
Relational database myhost not in relational database directory. SQLCODE=-950

I have an RDB set up on the i5/OS and it is named "PREPROD".
I tried using that in an earlier test and it did not work either.

Here is that code:
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');

Should I include the DATABASE parameter?

Fumigator
03-25-2009, 08:33 PM
I am always reluctant to suggest using a site that competes (at least indirectly) with Coding Forums, but in this case I really think you'd benefit from the expertise available over at dbforums.com.

(I apologize to CF for doing this, I hope you understand the only reason I did is because DB2 is not something we typically deal with here.)

I will also post the infomation on a -950 sqlcode error in case it helps you:


-950 THE LOCATION NAME SPECIFIED IN THE CONNECT STATEMENT IS INVALID OR
NOT LISTED IN THE COMMUNICATIONS DATABASE

Explanation: One of the following conditions applies:

* The location name is blank.

* The data type of the host variable is not character string.

* The length attribute of the host variable is greater than 16.

* The location name does not appear in the LOCATIONS column of the SYSIBM.LOCATIONS table, nor is it the name of the local DB2 subsystem.

System Action: The statement cannot be executed. The application process is placed in the unconnected state.

Programmer Response: If the location name is specified as the value of a host variable, ensure that the name is left justified in the host variable and, if necessary, padded on the right with blanks. If this is not the problem, either SYSIBM.LOCATIONS must be updated to include the specified name, or the specified name must be changed to match a name in SYSIBM.LOCATIONS.

SQLSTATE: 42705

tdavis
03-26-2009, 10:04 PM
Thanks for your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum