Using a Single Row configuration table in SQL Server database. Bad idea?

后端 未结 12 1954
终归单人心
终归单人心 2020-12-12 09:19

In developing a shopping cart application I\'ve found that I needed to save settings and configurations based on the administrator\'s preferences and requirements. This info

12条回答
  •  庸人自扰
    2020-12-12 09:59

    Sorry I come like, yeaars later. But anyways, what I do is simple and effective. I simply create a table with three () columns:

    ID - int (11)

    name - varchar (64)

    value - text

    What I do before creating a new config column, updating it or reading is to serialize the "value"! This way I am sure of the type (Well, php is :) )

    For instance:

    b:0; is for BOOLEAN (false)

    b:1; is for BOOLEAN (true)

    i:1988; is for INT

    s:5:"Kader"; is for a STRING of 5 characters length

    I hope this helps :)

提交回复
热议问题