unable to insert the image in MySQL [duplicate] - mysql

This question already has answers here:
How to use LOAD_FILE to load a file into a MySQL blob?
(6 answers)
Closed 6 years ago.
I'm trying to insert the image in MySQL whenever i tried to add the image it showed null value. Pls help me to add the image. I've give the correct path but still error has occurred
create table image3(id int, image longblob not null);
insert into image3(id,image)values(571185, load_file('D:\Images\3.jpg'));

The function load_file() returns the string representation of the file (it only works with text files).
What you're trying to do is insert binary data.
EDIT I was wrong, disregard the answer, instead look at this one: Load_File doesn't work
EDIT 2 Could it be that you have to use / instead of \? I know windows uses \ for path separators, but it's quite frankly the only OS to do so. Therefore I can imagine that MySQL (being multiplatform) uses "the correct separators".

Related

How to add extra folder to multiple paths stored in MySQL database? From `Folder\file.jpg` to `Folder\New Folder\file.jpg`? [duplicate]

This question already has answers here:
Update a column value, replacing part of a string
(6 answers)
Closed 2 years ago.
Details:
I have stored physical paths into MySQL table. I have moved all content to a new folder.
This is the data in the database:
Current data---
g:\Folder1\File 1.jpg
g:\Folder1\Excel File.xlsx
g:\Folder1\Test.js
Desired change:
Here is what I'd like to achieve, add an extra folder to the path before the filename.
Desired---
g:\Folder1\New Folder\File 1.jpg
g:\Folder1\New Folder\Excel File.xlsx
g:\Folder1\New Folder\Test.js
Question
How can I achieve this? And just for future, how can I remove a specific folder from the path?
Simply use REPLACE as explained also in this SO question
UPDATE table
SET fied = REPLACE(field, 'g:\Folder1\', 'g:\Folder1\New Folder\')
It is untested so you may have to fix the \ escaping
Since REPLACE gives you the ability to replace the string with another one you can just modify the strings to "add or remove folders"
Use replace function:
SELECT replace(filename, "Folder1\\", "Folder1\\New Folder\\")
FROM your_table;
You can specify a path from drive letter to avoid random data being replaced.

Code to insert Rows to a Table in phpMyAdmin [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
I am trying to add rows to my table using the code below. I keep getting an error. I doesn’t like the colons and if I take them out (although I need them in there) it then doesn’t like the 356’s. If I remove them it then doesn’t like something else.
I am using phpMyAdmin and thought I was using MySQL but the error messages mention MariaDB.
BTW, the book I am working through shows ‘ ‘ around the values to be inserted but I have found I can only insert values surrounded by “ “.
What do I need to change to get this working in phpMyAdmin?
INSERT INTO colours (ID, ColourCode)
VALUES
(“356-30-127”, “356-30-127 : Red”),
(“356-30-128”, “356-30-128 : White”);
For data insertion you have to use " or ' in string type
check below query it works
create table colours (ID varchar(200),ColourCode varchar(200));
INSERT INTO colours (ID, ColourCode)
VALUES ('356-30-127', '356-30-127 : Red'),
('356-30-128', '356-30-128 : White');
http://sqlfiddle.com/#!9/2a14a8/1

Cannot insert ' into my MySQL database in java [duplicate]

This question already has answers here:
How to escape single quotes in MySQL
(19 answers)
Closed 5 years ago.
I have designed java application & mysql database. Textfield also allow to accept whole characters. MySQL database data collation is set to utf8-default & MySQL server version is 5.7. I can type ' character in textfield. But I cannot execute sql syntax with ' in my query.
ex. Name's is not working, but names is working.
Try using an extra ' character
If the name is O'Brain , use it as O''Brain
For example
Select * from employees where name like 'O''Brain'
Make sure you gave same name to your database column name, where you parsing value from the android app.
or
specify your code so we can get more idea.

why won't mySQL let me SET return=1? [duplicate]

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 7 years ago.
It makes no sense. I have a TINYINT field that is either 0 or 1 and I'm trying to set it like this:
UPDATE db_products SET return='1' WHERE product_id=342343434
But it tells me there's a mySQL syntax error. What am I doing wrong here? Is the problem that the field is called return? If so, how do I get around it without changing it?
In most cases, you can get around reserved word problems by enclosing with "ticks"; the quote-like thing that usually shares the ~ key.
UPDATE db_products SET `return`='1' WHERE product_id=342343434

How to UPDATE just part of a text entry in mysql? [duplicate]

This question already has answers here:
Replace a word in BLOB text by MySQL
(3 answers)
Closed 9 years ago.
I have a column in my database that has the absolute URLs to images.
I've just transferred the entire website to another folder so the URLs of the images have changed. So for eg. if the URL of an image in the image_URL column was like:
http://www.mysite.com/images/myimage.jpg
I need to update it like this:
http://www.mysite.com/newfolder/images/myimage.jpg
The type for the image_URL column is TEXT. But I need to update it ONLY if the URL being used is "mysite" and not "externalsite".
What's the right SQL to use? I'm very familiar with SQL UDATE commands but not where I need to update only PART of a column value.
UPDATE table SET image = REPLACE(image, "http://www.mysite.com/images/", "http://www.mysite.com/newfolder/images/")
Sure, just do a LIKE search for 'mysite' to get all the URL's. Then one by one, change the text and resave it to your dB.
lee