467,923 Members | 1,819 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

Select From Db2 W/php Error

SimonJ621
I am trying to select from a DB2 database with PHP. To my knowledge, the connection is being made, but the select statement won't run. The following is the error I receive:

Warning: odbc_exec() [function.odbc-exec]: SQL error: [IBM][CLI Driver][DB2/AIX64] SQL0644N Invalid value specified for keyword "CONCURRENCY" in statement "<ATTRIBUTE-STRING>". SQLSTATE=42615 , SQL state 42615 in SQLExecDirect in C:\wamp\www\db.php on line 24
I can't find much help online, which is why I am posting here. Any help would be much appreciated as I have never attempted to use DB2. Following is my PHP code:

[PHP]<?php

function dbconnect($verbose) {
$dbname = "**";
$username = "**";
$password = "**";

$dbconn = odbc_pconnect($dbname, $username, $password);

if (($verbose == TRUE) && ($dbconn == 0 )) {
echo("connection to database failed.");
$sqlerror = odbc_errormsg($dbconn);
echo "<br /><br />".$sqlerror."<br /><br />";
}

return($dbconn);
}


function display($dbconn) {
$select_stmt = "SELECT * FROM blabla";

if ($dbconn != 0) {
$result = odbc_exec($dbconn, $select_stmt);
if ($result == 0) {
echo "SELECT statement failed.<br />";
$sqlerror = odbc_errormsg($dbconn);
}
else {
odbc_result_all($result);
}
}
}

$verbose = TRUE;
$dbconn = dbconnect($verbose);

display($dbconn);


?>[/PHP]


Thank you for all the help,

Jason
--------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/
Aug 15 '07 #1
  • viewed: 2113
Share:
3 Replies
Purple
Expert 256MB
Hi Jason,

What platform is the webserver running on ?

Does the odbc datasource test ok ?

Regards Purple
Aug 15 '07 #2
SimonJ621
The datasource tests ok. I have the DB2 client on my Windows machine but the server itself runs on a UNIX box.
Aug 16 '07 #3
SimonJ621
I used db2_connect instead of the odbc functions and it worked find. The following code worked:

[PHP]$conn = db2_connect($dbname, $username, $password);

if ($conn) {
$sql = "SELECT * FROM Table1";
$stmt = db2_prepare($con, $sql);
db2_execute($stmt);

$rows = array();
$i = 0;

while (db2_fetch_row($stmt)) {
$rows[$i] = db2_result($stmt, 0);
echo $rows[$i]."<br />";
$i++;
}
}
else {
echo "Connection failed. <br />";
echo db2_conn_errormsg();
}[/PHP]

Thanks again.

Jason
------------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/
Aug 17 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Greg Bryant | last post: by
9 posts views Thread by Kevin | last post: by
3 posts views Thread by Tcs | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.