By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

storing images in database

P: 3
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.
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE IF NOT EXISTS `products`(
  2.   `serial` int(11) NOT NULL auto_increment,
  3.   `name` varchar(20) collate latin1_general_ci NOT NULL,
  4.   `description` varchar(255) collate latin1_general_ci NOT NULL,
  5.   `price` float NOT NULL,
  6.   `picture` varchar(80) collate latin1_general_ci NOT NULL,
  7.   PRIMARY KEY(`serial`)
  8. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=7;
  9.  
and i have inserted the values for the above table also.
below is the one.....
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `products` (`serial`, `name`, `description`, `price`, `picture`) VALUES
  2. (1, 'View Sonic LCD', '19" View Sonic Black LCD, with 10 months warranty', 250, 'images/lcd.jpg'),
  3. (2, 'IBM CDROM Drive', 'IBM CDROM Drive', 80, 'images/cdrom-drive.jpg'),
  4. (3, 'Laptop Charger', 'Dell Laptop Charger with 6 months warranty', 50, 'images/charger.jpg'),
  5. (4, 'Seagate Hard Drive', '80 GB Seagate Hard Drive in 10 months warranty', 40, 'images/hard-drive.jpg'),
  6. (5, 'Atech Mouse', 'Black colored laser mouse. No warranty', 5, 'images/mouse.jpg'),
  7. (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');
  8.  
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...
Aug 20 '11 #1
Share this Question
Share on Google+
1 Reply


mwasif
Expert 100+
P: 801
In the above SQL examples you are saving images on disk and saving the path in DB. Follow this example to store images in DB.
Aug 24 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.