Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Posts
    4

    Unanswered: default field value

    how i can get default field value in mysql query?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    if you want to know what the default value for a certain column is, there's a new function in 4.1 called DEFAULT --

    select DEFAULT(foo) from yourtable

    if you just want to ensure the default value is assigned when you insert a row, omit the column from the statement --

    insert into yourtable (bar) values (937)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2005
    Posts
    4
    thnx, but it isn't it
    i have a table:
    Code:
    CREATE TABLE `users` (
      `id` bigint(20) NOT NULL auto_increment,
      `username` varchar(15) default NULL,
      `password` varchar(32) default NULL,
      `antihackpass` varchar(32) default NULL,
      `mail` varchar(255) default NULL,
      `signup_ip` varchar(15) default NULL,
      `signup_forip` varchar(15) default NULL,
      `active_kod` varchar(64) default NULL,
      `active` char(1) default NULL,
      `singup_time` bigint(20) default NULL,
      `lastlogin` bigint(20) default NULL,
      `lastlogin_ip` varchar(15) default NULL,
      `lastlogin_forip` varchar(15) default NULL,
      `upline` varchar(15) NOT NULL default 'pbanasiak',
      PRIMARY KEY  (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=17531 ;
    and default value for field 'upline' is 'pbanasiak', and i will get this information in mysql query.
    some description:
    Code:
    mysql_query('get me default value from upline field in users table :D ')

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    try this --

    mysql_query("select default(upline) from users")
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2005
    Posts
    4
    give me please full code - i try
    Code:
    $result = mysql_query("select default(upline) from users");
    $result2 = mysql_fetch_array($result);
    echo $result2[0];
    but it didn't work
    there's a new function in 4.1 called DEFAULT
    mysql or php version?

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sorry, i do not write php

    the DEFAULT function was introduced in mysql 4.1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jan 2005
    Posts
    4
    the DEFAULT function was introduced in mysql 4.1
    i have on server 4.0 but it is possible in older version then 4.1 - for example phpmyadmin know how to do but when i read code of phpmyadmin i don't know all - may by somebody know how to do?

Posting Permissions

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