Forum Moderators: open
Essentially, I've written a PHP function to shift uploaded files to a relavent folder given their extention, insert two fields into the appropriate table and return the value for the key field.
These two fields are the timestamp and a string.
The query I am using is
INSERT INTO xml (timeChanged, filename) VALUES (1148825487, 'id2_MDSu7VS_
sample.xml')
I've included below my results from the mySQL command line client, which includes the full table description and mySQL version.
I'd greatly appreciate any comments on this. I'm trying to avoid changing the type to INTEGER.
Thanks for reading this.
-----------
Your MySQL connection id is 188 to server version: 5.0.21-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use vortex
Database changed
mysql> INSERT INTO xml (timeChanged, filename) VALUES (1148825487, 'id2_MDSu7VS_
sample.xml');
ERROR 1292 (22007): Incorrect datetime value: '1148825487' for column 'timeChang
ed' at row 1
mysql> describe xml
-> ;
+-------------+-------------+------+-----+-------------------+----------------+
¦ Field ¦ Type ¦ Null ¦ Key ¦ Default ¦ Extra ¦
+-------------+-------------+------+-----+-------------------+----------------+
¦ fileid ¦ int(11) ¦ NO ¦ PRI ¦ NULL ¦ auto_increment ¦
¦ filename ¦ varchar(40) ¦ YES ¦ ¦ NULL ¦ ¦
¦ owner ¦ int(11) ¦ YES ¦ ¦ NULL ¦ ¦
¦ comment ¦ varchar(50) ¦ YES ¦ ¦ NULL ¦ ¦
¦ timeChanged ¦ timestamp ¦ YES ¦ ¦ CURRENT_TIMESTAMP ¦ ¦
¦ perms ¦ int(11) ¦ YES ¦ ¦ NULL ¦ ¦
¦ title ¦ varchar(50) ¦ YES ¦ ¦ NULL ¦ ¦
¦ checkedOut ¦ tinyint(1) ¦ YES ¦ ¦ NULL ¦ ¦
¦ valid ¦ tinyint(1) ¦ YES ¦ ¦ NULL ¦ ¦
+-------------+-------------+------+-----+-------------------+----------------+
9 rows in set (0.02 sec)
mysql>
INSERT INTO xml (filename) VALUES ('id2_MDSu7VS_
sample.xml');
The integer I was inserting is the result of the PHP strtotime function that returns the number of seconds since 1970.
From using other databases that's the way I'd been shown by other graduated computer science students. Particularly when i had to use MS Access, comparing dates was a nightmare so I've always gone for the integer type approach so that march 2006 > feb 2005.
Now that I'm moving into using a decen database package instead of Access, which has its limitations then I can now use easier and less code :) Just found this forum as I'm getting a coursework done. Very informative and educating forum.
Cheers for the quick reply mate.