Skip to content

Instantly share code, notes, and snippets.

@phpdave
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave/72927dcb9fd5c5c35c20 to your computer and use it in GitHub Desktop.
Save phpdave/72927dcb9fd5c5c35c20 to your computer and use it in GitHub Desktop.
PHP DB2 connect prepare and execute a select statement with binded parameters
<?
$options = array('i5_lib' => 'MYLIB' ,'i5_libl' => 'MYLIB', 'i5_naming' => DB2_I5_NAMING_ON,'autocommit' => DB2_AUTOCOMMIT_OFF, 'cursor' => DB2_SCROLLABLE);
$db2Connection = db2_connect('DBNAME','USER', 'PASSWORD', $options);
if (!$db2Connection) { echo "false - Connection failed.";exit(); }
$sql_query="SELECT ALBUM.*
FROM ALBUM
WHERE ID = ?";
$sql_statement = db2_prepare($db2Connection, $sql_query);
if($sql_statement ===false) {echo 'Prepare Failed - Error: ' . db2_stmt_error() . "|".db2_stmt_errormsg() ;}
$ID=1;
db2_bind_param($sql_statement, 1, "ID", DB2_PARAM_IN);
db2_execute($sql_statement);
$row = db2_fetch_assoc($sql_statement);
var_dump($row);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment