Re: MySQL, PHP or ghost?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Peter --

...and then Peter Beckman said...
% 
% Seems that either I don't understand mysql, or something.

Looks like it, though I admit that the manual doesn't adequately explain
your results.  Check out section 6.2.2.4 for details.


% 
% My table, with the non-important things removed...
...
% 
% So my assumption is that if I insert with year="" it should use the
% default.  Or at least 0000.

That makes sense.  And so what is the default?  Looks like it is, for
some reason, 2000.  [This isn't a TIMESTAMP field, so we don't
necessarily expect it to be "this year".]


% 
...
%     mysql> update plate set year="" where pid=65;
...
%     +-----+---------+------+-
%     |  65 | DVF0343 | 2000 |
%     +-----+---------+------+-
% 
% 2000?  What?  Why?  Confused.  PHP or Mysql fault?

Looks like it's standard mysql behavior:

  mysql> create table ytest (pid int unsigned not null auto_increment primary key, y year(4));
  Query OK, 0 rows affected (0.00 sec)

  mysql> describe ytest;
  +-------+------------------+------+-----+---------+----------------+
  | Field | Type             | Null | Key | Default | Extra          |
  +-------+------------------+------+-----+---------+----------------+
  | pid   | int(10) unsigned |      | PRI | NULL    | auto_increment |
  | y     | year(4)          | YES  |     | NULL    |                |
  +-------+------------------+------+-----+---------+----------------+
  2 rows in set (0.00 sec)

  mysql> insert into ytest values ('',1),('',''),('','2000');
  Query OK, 3 rows affected (0.00 sec)
  Records: 3  Duplicates: 0  Warnings: 4

  mysql> select * from ytest;
  +-----+------+
  | pid | y    |
  +-----+------+
  |   1 | 2001 |
  |   2 | 2000 |
  |   3 | 2000 |
  +-----+------+
  3 rows in set (0.00 sec)

  mysql> update ytest set y = "" where pid = 3;
  Query OK, 0 rows affected (0.00 sec)
  Rows matched: 1  Changed: 0  Warnings: 1

  mysql> select * from ytest;
  +-----+------+
  | pid | y    |
  +-----+------+
  |   1 | 2001 |
  |   2 | 2000 |
  |   3 | 2000 |
  +-----+------+
  3 rows in set (0.00 sec)

  mysql> update ytest set y = '0' where pid =3 ;
  Query OK, 0 rows affected (0.00 sec)
  Rows matched: 1  Changed: 0  Warnings: 0

  mysql> update ytest set y = '45678' where pid = 2;
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1  Changed: 1  Warnings: 1

  mysql> select * from ytest;
  +-----+------+
  | pid | y    |
  +-----+------+
  |   1 | 2001 |
  |   2 | 0000 |
  |   3 | 2000 |
  +-----+------+
  3 rows in set (0.00 sec)

Note that I sometimes get warnings and sometimes don't.  I haven't dug
into them, though.


% 
% Beckman
% ---------------------------------------------------------------------------
% Peter Beckman                                                  Internet Guy
% beckman@purplecow.com                             http://www.purplecow.com/
% ---------------------------------------------------------------------------


HTH & HAND

:-D
-- 
David T-G                      * There is too much animal courage in 
(play) davidtg@justpickone.org * society and not sufficient moral courage.
(work) davidtgwork@justpickone.org  -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/      Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

Attachment: pgp00057.pgp
Description: PGP signature


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux