SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to update database default value

    When I start my website with a user log in system. I offer every user free 20mb data storage.
    Now I want to upgrade the default value to 100mb and affect every user. How do I do that.
    Here's the code:
    Code:
    $mysqli->query("CREATE TABLE `user` (
       `id` INT NOT NULL AUTO_INCREMENT,
       `name` VARCHAR( 65 ) NOT NULL,
       `email` VARCHAR( 75 ) NOT NULL,
       `password` VARCHAR( 65 ) NOT NULL,
       ...
       `storage` SMALLINT NOT NULL default '20',
    PRIMARY KEY ( `id` ),
    UNIQUE (
       `email`
       )
     ) ENGINE = INNODB CHARACTER SET UTF8 COLLATE utf8_general_ci
    ")
    or die("DB error!");
    And what if in the future I offer them unlimited storage.
    Thank you,

  2. #2
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ketting00 View Post
    When I start my website with a user log in system. I offer every user free 20mb data storage.
    Now I want to upgrade the default value to 100mb and affect every user. How do I do that.
    Here's the code:
    Code:
    $mysqli->query("CREATE TABLE `user` (
       `id` INT NOT NULL AUTO_INCREMENT,
       `name` VARCHAR( 65 ) NOT NULL,
       `email` VARCHAR( 75 ) NOT NULL,
       `password` VARCHAR( 65 ) NOT NULL,
       ...
       `storage` SMALLINT NOT NULL default '20',
    PRIMARY KEY ( `id` ),
    UNIQUE (
       `email`
       )
     ) ENGINE = INNODB CHARACTER SET UTF8 COLLATE utf8_general_ci
    ")
    or die("DB error!");
    And what if in the future I offer them unlimited storage.
    Thank you,
    I don't know enough about MySQL, but is it not as easy as changing the "default '20' " to "default '100' " ?

    Failing that, and sorry if that was a ridiculous suggestion, I think you could set it using PHPMyAdmin too. I think you could edit the database table to add the default you want to that field.
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Shaun(OfTheDead) View Post
    I don't know enough about MySQL, but is it not as easy as changing the "default '20' " to "default '100' " ?
    Yes - the mySQL command to do that is:

    Code:
    ALTER TABLE `user` ALTER COLUMN `storage` SET DEFAULT '100';
    Of course that only affects future new users. You'd still need to run a regular table update for the existing users.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help.

    @ Shaun(OfTheDead) Any suggestion is better than never.


Bookmarks

Posting Permissions

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