Use php and wamp to Insert into mdb file that opened by another program

核能气质少年 提交于 2019-12-02 17:57:57

问题


I still need to solve this issue :(

Iam running a program name QMS on Windows XP to print ticket for patient. It use Access as database. I realize that in this database there is a table name rData. When someone need to print a ticket, it will insert a new row into this table, and the column Ticketno will be plus one.

You can see in the picture above it inserted a new row with Ticketno = 258 and printer print a ticket 258 for patient.

Next, Iam install Wamp on this computer and use php to insert into this table when I want. Here is my code to insert:

$dbName = "E:\\2.mdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
try {
    $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
$sql = "SELECT TOP 1 Ticketno FROM rdata WHERE ServiceId = 1 ORDER BY ID DESC";
$result = $db->query($sql);
$row = $result->fetch();
$num = $row['Ticketno']+1;
if(isset($_POST['submit'])){
    $sql = "INSERT INTO rdata(ServiceID, Ticketno, TicketFlag, TicketChain) VALUES(1,".$num.",0,';01')";
    $result = $db->query($sql);
}

After I run this code, I open the file via Microsoft Access and look at table rData, I see a new row is inserted (Ticketno = 259 in this case). And I press print button with hope that it will print a ticket with number = 260.

But, it still print a ticket 259, and insert into rData a row with Ticketno = 259, now I have 2 rows with Ticketno = 259. It seems like the program ignore my query.

I deleted this 2 rows and do again. However, before press print button, I quit the program and reopen. Now it print ticket 260. Can someone explain this to me? What should I do?

来源:https://stackoverflow.com/questions/42557272/use-php-and-wamp-to-insert-into-mdb-file-that-opened-by-another-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!