0

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.

1 Answer 1

1

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']);
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for response, i did edit my query as you have mention. I'm still getting a same error '#1048 - Column 'NewsVid' cannot be null'
Ok, now you need to check, if LOAD_FILE('Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4') returns some value. So what the function LOAD_FILE returning?
As I'm still new and learning, i understood that by LOAD_FILE i able to play my video file in browser by using php. Do point my mistake :)
Yes, but the MySQL error says: Column 'NewsVid' cannot be null and when you looks to your SQL command, you can see, that you adding output of LOAD_FILE('Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4') into NewsVid column. So maybe try to add Macintosh HD/Applications/XAMPP/xamppfiles/htdocs/video/Crime.mp4 only and then use LOAD_FILE when you will read data from database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.