ความหมายและการใช้งานฟังก์ชั่น odbc_fetch_array()
ฟังก์ชั่น odbc_fetch_array() คือ ฟังก์ชั่นที่ใช้คืนค่าข้อมูลในฐานข้อมูลที่อยู่ในลักษณะเป็นแถวหรือว่าเป็น record โดยตัวแปรผลลัพท์ที่มันคืนค่ากลับคืนมานั้นจะอยู่รูปแบบของตัวแปรอาร์เรย์ จากการประมวลผลด้วย odbc_exec() การเชื่อมต่อ PHP กับ SQL Server ได้หลาย ๆ Database ผ่าน ODBCใน PHP
รูปแบบ (Syntex)
odbc_fetch_array($variable)
อธิบาย
$variable คือ ตัวแปร
ตัวอย่าง
<html>
<head>
<title>MindPhp</title>
</head>
<body>
<?php
$con = odbc_conect("localhost", "root","", "dbtest") or die("ไม่สามารถเชื่อต่อฐานข้อมูลได้") ;
$str = "SELECT * FROM test";
$objExec = odbc_exec($con, $str) or die ("Error Execute [".$strL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?php
while($objResult = odbc_fetch_array($objExec))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["CustomerID"];?></div></td>
<td><?php echo $objResult["Name"];?></td>
<td><?php echo $objResult["Email"];?></td>
<td align="right"><?php echo $objResult["Budget"];?></td>
<td align="right"><?php echo $objResult["Used"];?></td>
</tr>
<?php
}
?>
</table>
<?php
odbc_close($con);
?>
</body>
</html>
ผลลัพธ์
odbc_fetch_array()
ข้อมูลอ้างอิง : www.w3schools.com