ODBC通过数据从PHP中的Ms Access数据库获取

时间:2018-01-21 08:45:41

标签: php database odbc ms-access-2007

我在PHP中从Microsoft Access Database 2007获取数据。它给出了一些错误

Warning: odbc_execute() expects parameter 2 to be array, string given in C:\xampp\htdocs\Project1\Attend.php on line 21

Notice: Use of undefined constant ODBC_FETCH_ASSOC - assumed 'ODBC_FETCH_ASSOC' in C:\xampp\htdocs\Project1\Attend.php on line 25

Warning: odbc_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Project1\Attend.php on line 25

Warning: odbc_next_result() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Project1\Attend.php on line 28

Warning: odbc_free_result() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Project1\Attend.php on line 41
{"status":0,"0":[]}

Attend.php

<?php



include 'Connection.php';


if(isset($_REQUEST["insert"]))
{
$reg = $_GET['reg'];
$ID = $_GET['ID'];

$sql = "select a.RegNo,b.RollNo,c.Standard,d.Division,b.Std_Name as StudentName,AttendanceDate,Attendance_Type,Remark
                                     from (((Attendance_mas as a 
                                     inner join Std_Reg as b on a.RegNo = b.RegNo) 
                                     inner join StandardMaster as c on a.Standard = c.stdid)
                                     inner join DivisionMaster as d on a.Division =d.DivisionID)
                                     where a.RegNo= '$reg' and a.yearid = '$ID' Order by AttendanceDate desc";
//$sql = "select * from Std_Reg";

$stmt = odbc_executec($conn, $sql);
print_r($stmt);
$result = [];
do {
    while ($row = odbc_fetch_array($stmt,ODBC_FETCH_ASSOC)){
       $result[] = $row; 
    }
} while (odbc_next_result($stmt));

if(count($result)>0)
{
    $result1['status']=1;//"Login successfully";
    array_push($result1,$result);
}
else
{
     //$result[]="null";
    $result1['status']=0;//"Record not found";
    array_push($result1,$result);
}
odbc_free_result($stmt);
odbc_close($conn); //Close the connnectiokn first

echo json_encode($result1); //You will get the encoded array variable
}

?>

0 个答案:

没有答案