as400 db2 iseries を使用していますが、データベースからデータを取得できません。for ループを使用すると正常に動作しますが、while ループを使用するとエラーが発生します。ここで、参照用にコードを更新します...
コード:
$database = 'xxxxxx';
$user = 'xxx';
$password = 'xxx';
$hostname = 'x.x.x.x';
include('adodb.inc.php');
$db = ADONewConnection('odbc');
$dsn = "DRIVER={iSeries Access ODBC Driver};SYSTEM=$hostname;DATABASE=$database;";
if($db->Connect($dsn,$user,$password)){
$query = "SELECT * FROM IND0301F.XMAGLF0 WHERE XMCDMA='I01' AND XMCDUB=''";
$res = odbc_exec($query);
while( $row = odbc_fetch_array($res) ) {
echo $row['XMARCD']; exit;
}
}
<?php // no direct access
//defined('_JEXEC') or die('Restricted access');
?>
<?php
set_time_limit(0);
//echo "Current User is ". $uname=$_SESSION['username'];
?>
<?php
$database = 'IND0301F';
$user = 'QUSER';
$password = 'QUSER';
$hostname = '10.10.0.30';
?>
<?php
include('adodb.inc.php');
$db = ADONewConnection('odbc');
$dsn = "DRIVER={iSeries Access ODBC Driver};SYSTEM=$hostname;DATABASE=$database;";
if($db->Connect($dsn,$user,$password)){
$sql_count = "SELECT COUNT(*) FROM IND0301F.XMAGLF0 WHERE XMCDMA='I01' AND XMCDUB=''";
$rs_count = $db->Execute($sql_count);
$result_count = $rs_count->GetArray();
$count_rd = $result_count[0][0];
$sql = "SELECT * FROM IND0301F.XMAGLF0 WHERE XMCDMA='I01' AND XMCDUB=''";
$rs = $db->Execute($sql);
if (!$rs) echo "<p>no records</p>";
else
{
$result = $rs->GetArray();
?>
<tr>
<th>VRVCODE</th>
<th>Description</th>
<th>UOM</th>
<th>WH</th>
<th>Stock </th>
<th>Material Requested but PO not placed</th>
<th>Ordered</th>
<th>Items expected to deliver in 1 month</th>
<th>Items expected to deliver in 2 month</th>
<th>Items expected to deliver in 3 month</th>
<th>Items expected to deliver in morethan 3 month</th>
</tr>
<?php
for($i=0;$i<$count_rd;$i++)
{ ?>
<tr class="odd_gradeX">
<?php
for($j=0;$j<=53;$j++)
{ // 0 3 4 7 9 17 18 19 20 21 22
if(($j != 1) && ($j != 2) && ($j != 10) && ($j != 5) && ($j != 6) && ($j != 8) && ($j != 11) && ($j != 12)
&& ($j != 13) && ($j != 14) && ($j != 15) && ($j != 16)
&& ($j != 23) && ($j != 24) && ($j != 25) && ($j != 26) && ($j != 27)
&& ($j != 28) && ($j != 29)
&& ($j != 30) && ($j != 36) && ($j != 37) && ($j != 38) && ($j != 39)
&& ($j != 31) && ($j != 32) && ($j != 33) && ($j != 34) && ($j != 35)&& ($j != 40) && ($j != 41) && ($j != 42) && ($j != 43) && ($j != 44) && ($j != 45) && ($j != 46) && ($j != 47) && ($j != 48) && ($j != 49) && ($j != 50) && ($j != 51) && ($j != 52) && ($j != 53)){
?>
<?php
if(($j == 9)||($j == 17)||($j == 18) ||($j == 19) ||($j == 20) ||($j == 21) ||($j == 22)){ ?>
<td align="right">
<?php } elseif(($j == 3)){ ?>
<td align="left"> <?php }
else { ?>
<td align="center"> <?php } ?>
<?php
if($result[$i][$j]!='')
{
?> <?php
echo $result[$i][$j]; ?> <?php
echo " ";
} }
?>
</td>
<?php } ?>
</tr><?php
} ?>
<?php
}
} else {
echo "Not working";
echo 'SQLSTATE: '.$db->ErrorNo()."<br>";
echo 'Message: '.$db->ErrorMsg()."<br><br>";
}
?>