简体   繁体   English

mysql的到达日期和离开约束(检查约束)

[英]arrival date and departure constraint with mysql (check constraint)

I want to implement a web app with php and mysql, to book an hotel and I want to create a constraint so the date of departure cannot be before the arrival date here are the method that I've tried without success : ALTER TABLE reservation WITH CHECK ADD CONSTRAINT CONSTRAINT check_dates CHECK ( DATEARRIVEE < DATEDEPART) messe error: You have an error in your SQL syntax; 我想用php和mysql实现一个Web应用程序,预定一家酒店,并且我想创建一个约束,因此出发日期不能早于到达日期,这里是我尝试过的没有成功的方法: ALTER TABLE reservation WITH CHECK ADD CONSTRAINT CONSTRAINT check_dates CHECK ( DATEARRIVEE < DATEDEPART)错误:您的SQL语法有误;请ALTER TABLE reservation WITH CHECK ADD CONSTRAINT CONSTRAINT check_dates CHECK ( DATEARRIVEE < DATEDEPART)错误。 check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHECK ADD CONSTRAINT CONSTRAINT check_dates 检查与您的MySQL服务器版本相对应的手册,以在'CHECK ADD CONSTRAINT CONSTRAINT check_dates附近使用正确的语法

I suggest you to do the checks back-end side in your php code before inserting records in the table and front-end side with js. 我建议您先在php代码中进行后端检查,然后再在表中插入记录,并在前端插入js。 If the arrival date is > of the departure date you don't have to make a request to your server, so your js must handle this problem. 如果到达日期大于离开日期,则不必向服务器发出请求,因此您的js必须处理此问题。 For more security just before execute the query you can add another check. 为了在执行查询之前获得更高的安全性,您可以添加另一个检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM