mojeime
mojeime

Reputation: 21

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.

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). 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.

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?

Where XXX is country ID, ZZZZZ is client ID, YYYY is barcode string 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.

Thanks

Upvotes: 2

Views: 9903

Answers (3)

Ken Downs
Ken Downs

Reputation: 4827

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.

Upvotes: 1

wimvds
wimvds

Reputation: 12850

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).

A basic example (using PEAR Image_Barcode) can be found at Using barcodes in your web application.

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).

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).

Upvotes: 1

iDevlop
iDevlop

Reputation: 25272

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.

Upvotes: 0

Related Questions