Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: locking a row

  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts

    locking a row

    im considering locking one row to a table so that the table will always have a default value.

    im sure i can lock the table itself, and i know i can just use php to find the value and reject any delete query, but can i lock a single row id so that it cannot be removed just in the table config itself?
    Last edited by durangod; 02-20-2013 at 02:16 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Short answer: No.

    There are ways to accomplish row locking, but they only last so long as the connection to the DB is maintained. So you couldn't maintain a connection very well from PHP. You'd have to do it from, say, a command line window where you never closed the window.

    A better way to do this is probably to use a VIEW or STORED PROCEDURE. (Besides, DB purists will urge you to do *ALL* web-based work on the DB via one of those and *NEVER* make ad hoc SQL queries!)

    Your VIEW or PROC simply provides a default record if no record is found.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    durangod (02-20-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •