0

(Im so sorry that this is trivial but i am using SQL/php for the first time, I tried looking at the answers on this site and various other sites/videos but i dont understand what is going wrong) I'm creating a quiz where the questions are in the form of images, so a random image from a table must be chosen and displayed. I looked at many websites and I am currently following this page:

https://www.sqlshack.com/upload-multiple-images-sql-server/

I created the table using this code (which works)

$sql = "CREATE TABLE IF NOT EXISTS photo_table (photo_name_col VARCHAR(30), varBinaryData VARBINARY(100000000))";

(i used 10000000 instead of max because it throws a syntax error when I use max.

when i follow the tutorial and try to insert images it throws a syntax error and asks me to check the correct syntax in the manual, but i read the manual and could not find anything

$sql2 = "INSERT INTO photo_table(photo_name_col, varBinaryData) VALUES('image1', (SELECT * FROM OPENROWSET (Bulk N'C:\xampp\htdocs\drunknet.jpg', SINGLE_BLOB) AS T1))";
Vanessa
  • 31
  • 1
  • 6
  • 2
    If you are running MySQL like the tag indicates, you should not be following a SQL Server tutorial... – GMB Mar 03 '20 at 21:18
  • 1
    I'm going to classify this one as a typo. Not a typo in the code, but in your Google searches. You're following a tutorial for a different product than the one you're using. – David Mar 03 '20 at 21:21
  • https://stackoverflow.com/questions/34328601/how-to-insert-images-in-blob-in-mysql-table-using-only-sql-syntax-without-php - Oddly the same question (using sql server syntax to insert a picture into mysql). First answer has what you need. – JNevill Mar 03 '20 at 21:22
  • @JNevill I had already tried the LOAD_FILE command as stated in the answer to the question in the link, but it does not work for me, I don't understand what is going wrong? while creating the table I should put LONGBLOB as the type correct? I tired LONGBLOB and BLOB and TINYBLOB and IMAGE and other variations. – Vanessa Mar 04 '20 at 12:37
  • the error states: CALL TO UNDEFINED FUNCTION: LOAD_FILE() – Vanessa Mar 04 '20 at 13:13

0 Answers0