【发布时间】:2017-12-19 11:01:23
【问题描述】:
我正在使用 php 表单提交学生费用。如果单个用户提交该表单,一切正常,并且数据保存在 MySQL 数据库中。但是如果我使用 5-10 不同提交该表单> 系统同时,然后 MySQL 只插入两个或三个用户的数据。 我正在为 invoice_id 使用触发器:
CREATE TRIGGER `test_trig` BEFORE INSERT ON `student_fee_transaction_details`
FOR EACH ROW BEGIN
SET NEW.inv_no=(SELECT CONCAT(NEW.school_id,'-', SUBSTRING_INDEX( inv_no, '-', -1 ) +1 ) AS inv_number_new
FROM student_fee_transaction_details
WHERE id IN (SELECT MAX( id ) FROM student_fee_transaction_details WHERE school_id = NEW.school_id
));
END
这是我要插入的 php 代码
insert into student_fee_transaction_details (id,fine_amount,interest_amount,handling_charges,
institute_id,school_id,student_id,class_id,section_id,admission_no,fees_amount,payment_date,
payment_mode,paid_amount,inv_date,inv_ref_no,inv_no,inv_status,session,payment_bank,payment_type,
cheque_dd_no,payment_chanel,fee_due_date,cheque_dd_date,remarks,deposit_bank_id)
values('','$fine_amt','$interest_amt','$hand_charge','$ins_id','$sch_id','$stu_id','$cls_id',
'$sec_id','$adm_no','$total_fee_paid_amt','$pay_dt','Manual','$total_paid_amt','$inv_dt',
'$ref_no','1898776','Invoiced','$session','$bank_nm','$pay_type','$dd_chq_no','web',
'$fee_due_date','$dd_cheq_dt','$swipe_remarks','$deposit_bank')";
$result_inv_master = $con->query($qry_inv_master);
【问题讨论】:
-
您实际上是在为您的下一个 inv_no 选择“max + 1”,这意味着您已经设计了一个单用户系统。使用自动增量或序列或 MySQL 提供的任何东西来使并发使用成为可能。
标签: php mysql bulkinsert