Jump to content

Need Help with Table Structure


SalientAnimal

Recommended Posts

Hi Guys/Gals,

 

I have a database that curerntly has 4 tables in it that are all linked to each other with a refernce number. I would like to create another table, one that will store all my attachments. I have never done nor create a table that stores any kind of attachments and need some advice in how to go about with creating the table:

What fields do have to have in the table?

What is the correct structure for each field in the table?

I need to have the reference number also saved in this table as it is my unique identifier.

How do I then save the file into the database using the attachment function from a PHP form?

 

Thanks.

 

Link to comment
Share on other sites

The table needs to contain all the data that you think is relevant.

 

Files should not be stored in databases, but in the filesystem. You would store the location of the file in your table.

 

Hi Jesirose,

 

Can you maybe give me some guidance of how to do all this? Keep in mind I would need to add an "Attach Document" field to my form.

 

Thanks

Link to comment
Share on other sites

Depends if you want to store your attachments in the filesystem:

CREATE TABLE attachments (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    reference_number INT UNSIGNED NOT NULL,
    file_path VARCHAR(255) NOT NULL,
    created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
) TYPE=InnoDB;
/* This may have to be a foreign key reference */
ALTER TABLE attachments ADD INDEX (reference_number);

 

Or in your database:

CREATE TABLE attachments (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    reference_number INT UNSIGNED NOT NULL,
    file_name VARCHAR(255) NOT NULL,
    file_data BLOB NOT NULL,
    created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
) TYPE=InnoDB;
/* This may have to be a foreign key reference */
ALTER TABLE attachments ADD INDEX (reference_number);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.