0

Actually i want to make read-only some row in my table of a database .

For Example my table has 3 columns (1.no. (int) , 2. Lenght , 3. Status ) and 6 records (1.['1','512','ok'] , 2.['2','512','ok'] , 3.['3','512','no'] , 4.['4','512','ok'] , 5.['5','512','no'] )

u can see most are same just 3 records are ok and 2 are no those which are ok i need it to make read only means once it status is ok no one can edit that record only read the record.

My script is in PHP and MySQL .

tereško
  • 58,060
  • 25
  • 98
  • 150
Soumo Gorai
  • 143
  • 3
  • 13
  • You should control from within your script whether someone has the privilege to update a record or not, not use MySQL to "lock" rows because it's not MySQL's job, it's your job to determine who can and can't write to the table. – Michael J.V. May 06 '11 at 13:30

2 Answers2

1

A question similar to this one has already been asked and answered here.

Essentially, you would create a database trigger for before_update and before_delete, that identifies the rows that you want to preserve and throws an error if a modification is attempted on said rows.

Community
  • 1
  • 1
saghaulor
  • 140
  • 4
1

I think you can only lock the tables rather then the rows, so what I suggest you do is create another column called locked which has a 0 or 1 for it's value and do something like this:

UPDATE table SET column = X WHERE id = 22 AND locked = 0 

That would be your best method IMO

RobertPitt
  • 56,863
  • 21
  • 114
  • 161