虽然 9.5 K 行并不多,但相关的数据量需要一些时间来传输。
因此——一般来说——我建议在服务器端运行值验证。AJAX 是很容易做到这一点的正确技术。
加载所有 9.5 K 行只是为了找到一个特定的行,这绝对是一种资源浪费。对单个值运行SELECT 查询。
在客户端/AJAX 公开 PHP 功能
看看xajax 项目,它允许在客户端将整个 PHP 类或单个方法公开为 AJAX 方法。此外,xajax 有助于客户端和服务器之间的参数交换。
索引要搜索的属性
请确保保存条形码值的列已编入索引。如果验证过程趋于缓慢,请注意MySQL 表扫描。
避免表扫描
To avoid table scans and keep your queries run fast, do use fixed sized fields. E.g. VARCHAR() besides other types makes queries slower, since rows no longer have a fixed size. No fixed-sized tables effectively prevent the database to easily predict the location of the next row of the result set. Therefore, you e.g. CHAR(20) instead of VARCHAR().
Finally: Security!
Don't forget, that any data transferred to the client side may expose sensitive data. While your 9.5 K rows may not get rendered by client's browser, the rows do exist in the generated HTML-page. Using Show source any user would be able to figure out all valid numbers.
Exposing valid barcode values may or may not be a security problem in your project context.
PS: While not related to your question, I'd propose to use PHPexcel for reading or writing spreadsheet data. Beside other solutions, e.g. a PEAR-based framework, PHPExcel depends on nothing.