简体   繁体   English

在数据库中存储/生成条形码字符串(mysql)

[英]storing/generating barcode string in database (mysql)

I never worked with barcode and now i must design a whole app with barcode support. 我从未使用过条形码,现在我必须设计一个带有条形码支持的整个应用程序。 I was wondering what type of barcode i can use, how can i make shure that barcode string is uniqe and how would i store that in MySQL. 我想知道我可以使用哪种类型的条形码,如何确保条形码字符串是唯一的,以及如何将其存储在MySQL中。

I was thinkin about generating some barcode strings and print them to stickers so my clients can use them. 我正在考虑生成一些条形码字符串并将其打印到贴纸上,以便我的客户可以使用它们。 I was thinking to do generating part in php/mysql then prepare for printing (render in pdf). 我当时想在php / mysql中生成部分,然后准备打印(以pdf格式呈现)。 Let's say i generated 100 strings and store them to database and next time i want to generate another 200 that must be unique. 假设我生成了100个字符串并将其存储到数据库中,下次我想生成另外200个必须唯一的字符串。

I don't even know where to begin with string. 我什至不知道从字符串开始。 What information can i store in barcode string? 我可以在条形码字符串中存储哪些信息?

Can i do this: XXX-ZZZZZ-YYYY-autincrementID? 我可以这样做:XXX-ZZZZZ-YYYY-autincrementID吗?

Where XXX is country ID, ZZZZZ is client ID, YYYY is barcode string ID. 其中XXX是国家/地区ID,ZZZZZ是客户ID,YYYY是条形码字符串ID。 Should i use surrogative key for my primary key or should i split those to multiple tables? 我应该将代理键用作主键还是应该将其拆分到多个表中?

Did i mentioned that all autoincrementID's should start from 1 for each client :) I am sooooo confused about all this. 我是否提到过,每个客户端的所有autoincrementID都应从1开始:)我对此感到非常困惑。

Thanks 谢谢

First decide on the barcode format you want to use. 首先确定您要使用的条形码格式。

Then check if there is a PHP implementation out there (there will be for most - if not all - barcode formats). 然后检查是否有PHP实现(大多数-如果不是全部-条形码格式)。

A basic example (using PEAR Image_Barcode ) can be found at Using barcodes in your web application . 一个基本示例(使用PEAR Image_Barcode )可以在Web应用程序中的“使用条形码”中找到。

You just store the text in the DB and can generate the corresponding image using the Image_Barcode class (it supports Code 39, Code 128, EAN 13, INT 25, PostNet and UPCA). 您只需将文本存储在数据库中,就可以使用Image_Barcode类(它支持Code 39,Code 128,EAN 13,INT 25,PostNet和UPCA)生成相应的图像。

I once wrote an app creating EAN 13 barcodes, don't remember which lib I used though (I'll check at home if I can find the source). 我曾经写过一个用于创建EAN 13条码的应用程序,但不记得我使用了哪个库(如果能找到源,我会在家检查)。

A barcode is just a way to print and/or read a string. 条形码只是一种打印和/或读取字符串的方式。 It involves 它涉及

  1. special fonts, 特殊字体
  2. some calculation (for check digits) 一些计算(用于校验位)

Your first step should be to identify wich barcode you need to support. 第一步应该是识别需要支持的条形码。 Many companies manufacturing barcode printers and readers also provide some help about that. 许多制造条形码打印机和读取器的公司也提供了一些帮助。

I found some great help here , including free fonts. 我在这里找到了很大的帮助,包括免费字体。 It's a french site but a few things are available in English. 这是一个法语网站,但英语提供了一些功能。

We need to separate some concerns. 我们需要分开一些关注点。

First is the action of printing any given string as a barcode. 首先是将任何给定的字符串打印为条形码的操作。 The other answers talk about how to do that. 其他答案讨论如何做到这一点。

The other action has nothing to do with barcodes and is about database design. 另一个动作与条形码无关,与数据库设计有关。 Your example suggests the barcode will be a combination of values. 您的示例建议条形码将是值的组合。 However, I get the idea (correct me if I am wrong) that the larger application is not yet clearly spelled out. 但是,我有一个想法(如果我做错了,请纠正我),这个较大的应用程序尚未明确说明。 Therefore it does not matter what kind of "play" table you create for unique codes right now -- create whatever you want. 因此,现在为唯一代码创建哪种“播放”表并不重要-创建所需的任何内容。 When you know what values must be printed as barcodes, then we are into a database design question. 当您知道必须将哪些值打印为条形码时,我们就会陷入数据库设计问题。

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

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