-1
INSERT INTO items (id,name,image,price) VALUES('1','iphone 5s',LOAD_FILE('C:\xampp\htdocs\project\1.jpg'),300);

this statement cause error

INSERT INTO items (id,name,image,price) VALUES('1','iphone 5s',LOAD_FILE('C:\xampp\htdocs\project\1.jpg'),300)
MySQL said: Documentation

here is the error

#1048 - Column 'image' cannot be null
jww
  • 97,681
  • 90
  • 411
  • 885
  • Pick a single database engine - the code required will be specific to that engine. SQL Server has no load_file function. – SMor Nov 14 '18 at 03:22
  • i used maria db. – Anupama Dikkumbura Nov 14 '18 at 03:34
  • 3
    Possible duplicate of [MySQL LOAD\_FILE is not working as expected](https://stackoverflow.com/q/8229951/608639), [How do I use LOAD_FILE to insert value from a file into a table?](https://stackoverflow.com/q/14892219/608639), [LOAD_FILE returns NULL](https://stackoverflow.com/q/18721317/608639), etc. – jww Nov 14 '18 at 16:48

2 Answers2

0

Please double check the file path of your "1.jpg" or maybe look at the image format whether it is .jpg or .png.

Else, try this format:

LOAD_FILE('../1.jpg')

"Different backslash position"

I do not think you should mention the C:/xampp/htdocs/project because you are already in the project folder when you run your code.

Hopefully it is working.

Json
  • 23
  • 5
0

You must escape backslashes in any string:

... LOAD_FILE('C:\\xampp\\htdocs\\project\\1.jpg') ...

Or, since MySQL will 'correctly' interpret forward-slashes, even on Windows:

... LOAD_FILE('C:/xampp/htdocs/project/1.jpg') ...

(I assume image is declared BLOB or MEDIUMBLOB?)

Rick James
  • 135,179
  • 13
  • 127
  • 222