<html>
<head>
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Author" content="Zend Japan">
<meta http-equiv="Description" content="Prepare使用例">
<title>sample04</title>
</head>
<body>
<?php
//DB接続
require_once 'inc/dbconn.inc';

//改行
$eol = "\r\n";

//テスト用PF
$test_pf = 'ZTESTF';

//テストパラメーター
$test_prm1 = 'A001';
$test_prm2 = 'A003';

$query = 'SELECT ' .
'RTRIM(COLA) AS COLA, ' .
'RTRIM( CAST( COLO AS CHAR(18) ) ) AS COLO, ' .
'RTRIM( CAST( COLJ AS CHAR(18) ) ) AS COLJ, ' .
'COLP, ' .
'COLS  ' .
'FROM ' .
$test_pf .
//？記号のところにパラメータ値が入ります
' WHERE COLA BETWEEN ? AND ? ';

$stmt = db2_prepare($db_con, $query);
if(!$stmt){
	echo 'Prepareできませんでした<br>';
	echo db2_stmt_errormsg();

	db2_close($db_con);
    echo '</body></html>';
	return;
}

$result = db2_execute($stmt, array($test_prm1, $test_prm2));
if(!$result){
	echo 'SQLが実行できませんでした<br>';
	echo db2_stmt_errormsg();

	db2_close($db_con);
    echo '</body></html>';
	return ;
}

echo '<table border=1>' . $eol;
echo '<tr><th>COLA</th><th>COLO</th><th>COLJ</th><th>COLP</th><th>COLS</th></tr>' . $eol;

while(db2_fetch_row($stmt)) {
    $cola = db2_result($stmt, 'COLA');
    $colo = db2_result($stmt, 'COLO');
    $colj = db2_result($stmt, 'COLJ');
    $colp = db2_result($stmt, 'COLP');
    $cols = db2_result($stmt, 'COLS');

    echo '<tr>';
    echo '<td>'. $cola . '</td>';
    echo '<td>'. $colo . '</td>';
    echo '<td>'. $colj . '</td>';
    echo '<td>'. $colp . '</td>';
    echo '<td>'. $cols . '</td>';
    echo '</tr>' . $eol;
}

echo '</table>';

db2_close($db_con);

?>
</body>
</html>