SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    storing images in database

    hi all,
    i want to store an image in MYSQL database.please tell me whether the below sql syntax i have written is correct or not.
    Code:
    CREATE TABLE IF NOT EXISTS `products`(
      `serial` int(11) NOT NULL auto_increment,
      `name` varchar(20) collate latin1_general_ci NOT NULL,
      `description` varchar(255) collate latin1_general_ci NOT NULL,
      `price` float NOT NULL,
      `picture` varchar(80) collate latin1_general_ci NOT NULL,
      PRIMARY KEY(`serial`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=7;
    and i have inserted the values for the above table also.
    below is the one.....
    Code:
    INSERT INTO `products` (`serial`, `name`, `description`, `price`, `picture`) VALUES
    (1, 'View Sonic LCD', '19" View Sonic Black LCD, with 10 months warranty', 250, 'images/lcd.jpg'),
    (2, 'IBM CDROM Drive', 'IBM CDROM Drive', 80, 'images/cdrom-drive.jpg'),
    (3, 'Laptop Charger', 'Dell Laptop Charger with 6 months warranty', 50, 'images/charger.jpg'),
    (4, 'Seagate Hard Drive', '80 GB Seagate Hard Drive in 10 months warranty', 40, 'images/hard-drive.jpg'),
    (5, 'Atech Mouse', 'Black colored laser mouse. No warranty', 5, 'images/mouse.jpg'),
    (6, 'Nokia 5800', 'Nokia 5800 XpressMusic is a mobile device with 3.2" widescreen display brings photos, video clips and web content to life', 299, 'images/mobile.jpg');
    the "picture" field stores pictures in database.i have given there VARCHAR(80)
    i know for storing pictures we should give BLOB data type.
    but tell me whether the above syntax i have written will work or not.
    if not what would be the syntax...

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    the INSERT statement that you have shown will work fine for storing the image path in the VARCHAR(80) column

    storing the image itself in a BLOB is going to be a bit more difficult

    do you have a good reason for wanting to store the picture itself in the database?

    because most people don't do that
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i want to create and insert values in to the 'products' tables using
    "phpmyadmin".
    in "phpmyadmin" how to set collate latin1_general_ci and NOT NULL fields
    and AUTO_INCREMENT=7.
    whether i need to write the entire code in "phpmyadmin"
    or directly we can do in "phpmyadmin".
    tell me how to do directly in "phpmyadmin".

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    i'm sorry, i don't think you can store images in the database with phpmyadmin
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then we have to type the above code in mysql> prompt right.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    the above code (in post #1) is perfectly okay in phpmyadmin

    i thought you were asking about storing the actual images in a BLOB column
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then in "phpmyadmin".for collation i can select in drop down box.then how to select NOT NULL feature for any field.also for the "picture" field in the #1 table whether i need to select the option as image/jpeg in MIME type, and browser transformation as image.jpeg: inline
    or both are not necessary.


Bookmarks

Posting Permissions

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