First, I’m trying to store the `url` and `title` into a database from my “Read” section. I’ve created a database, database user and set a table with the name `read` with 2 columns (one for url and the other for link). This is where I’m stuck. I’m not exactly sure what I should put inside some of the options shown below.
Or should my PHP be setting this information from the array?
Also, I hope I’m not exposing any sensitive information here. Please let me know if I am.
This reply has been reported for inappropriate content.
Well, traq is the expert, but I can say something about it.
You only need Type (if it’s VARCHAR, which I guess you want here, you need Length too). Length is the maximum number of characters you expect on that field. something like 255 should be sufficient.
Other attributes (which you don’t need):
Default is exactly what you’d guess it is, in this case, I don’t think you want that.
Collation is the character encoding, you can set it globally for your database so you don’t need to add it again and again:
ALTER DATABASE databasename
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_unicode_ci;
Null if null is allowed for that column.
Index this is for indexing. That’s for read performance (look-up by index is very fast) and constraints (for example a foreign index is a constraint so that a value of that column has to reference a row by index in another table). You can use this if you want read performance (you probably do).
Regarding indexes you might want a 3rd column (or first usually) named ‘id’ or something, with an auto-incrementing primary key of type int. That’s common practice.
Hope @traq will correct me if I’m wrong or fill in where I missed anything :)
EDIT: InnoDB engine should be okay, I’m always using InnoDB.
I’m not sure why I should set an ID? What’s supposed to go there?
No, the only “user” would be me. I add what I read to my readability account and pull that data from the RSS feed.
I’m just trying to store that data in case I decide to do something with it later. Something like show what all I’ve read throughout the year. As for now, I’m just going to be outputting my latest article that I’ve read.
ID is your table index, every table should have it.
This number keeps track how many different unique entries you have. It starts at 1 and with every entry it auto increments. In the example you have how would you display ascending or descending data? You would only be able to sort it by url or title.
I would, so if you wanted to add extra info about the user down the road that data will be abstracted. Since you are the only user just pass 1 to user_id. or if you want to keep it real simple just add id (index, auto increment) to the read table.
CREATE TABLE IF NOT EXISTS `read` (
`id` tinyint(8) NOT NULL AUTO_INCREMENT,
`title` varchar(250) NOT NULL,
`url` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
You must be logged in to reply to this topic.