Last active
August 29, 2015 14:23
-
-
Save phpdave/72927dcb9fd5c5c35c20 to your computer and use it in GitHub Desktop.
PHP DB2 connect prepare and execute a select statement with binded parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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