使用日期范围搜索时优化mysql查询

时间:2017-01-12 16:57:58

标签: php mysql

我必须从搜索数据的日期和日期开始输入日期,目前我正在使用3个if语句进行搜索。这是正确的方法吗?或者是否有任何其他最佳实践可用于减少查询时间。建议吗?

export namespace BootDeviceSelector {
    export const noChange: 'None' = 'None';
    export type noChange = 'None';
    export const PXE_ISCSI: 'Pxe' = 'Pxe';
    export type PXE_ISCSI = 'Pxe';
}
export type BootDeviceSelector = BootDeviceSelector.noChange | BootDeviceSelector.PXE_ISCSI;

1 个答案:

答案 0 :(得分:0)

当您不想为sql注入创建孔时,不要将代码与数据混合 您可以将所有逻辑移动到查询中 ... and (? is null or regdate >= ?) and (? is null or regdate <= ?)
并发送另外四个参数[..., $from_date1, $from_date1, $to_date2, $to_date2]

相关问题