Jacob90
Jacob90

Reputation: 3

Inserting URL in MySQL

Im currently working on iOS application which populate videos in UITableView by using MySQL as rdbms and xampp as a web server. I am facing difficulty in inserting URL in MySQL table. To make it more clear, i have 3 column which is NewID, NewsTitle and NewsVid in the table. when i insert the URL by query such as:

INSERT INTO `dbnews`.`Newsfeed` (`NewsID`, `NewsTitle`, `NewsVid`) VALUES ('1', 'Today's news', LOAD_FILE('Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4'))

An error prompt "#1048 - Column 'NewsVid' cannot be null"

Hoping on providing a guide for me to tackle this issues since i am in process of learning.

Upvotes: 0

Views: 1054

Answers (1)

pes502
pes502

Reputation: 1587

At first - you have got unescaped char ' in your SQL command - here: 'Today's news':

INSERT INTO `dbnews`.`Newsfeed` (`NewsID`, `NewsTitle`, `NewsVid`) VALUES ('1', 'Today's news', LOAD_FILE('Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4'))
                                                                                      ^ HERE

Edit your SQL to (you need to escape the ' with backslash \):

INSERT INTO `dbnews`.`Newsfeed` (`NewsID`, `NewsTitle`, `NewsVid`) VALUES ('1', 'Today\'s news', LOAD_FILE('Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4'))

UPDATE BASED ON COMMENTS:

And then you can try to store only link to file in database, no output of LOAD_FILE function. So your updated command will looks like:

INSERT INTO `dbnews`.`Newsfeed` (`NewsID`, `NewsTitle`, `NewsVid`) VALUES ('1', 'Today\'s news', 'Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4')

You can use LOAD_FILE when you will read data from database, something like:

// DB CONNECT
// DB READ DATA
LOAD_FILE($row['NewsVid']);

Upvotes: 1

Related Questions