I am facing issues while inserting multiple records in sql server using php.
Here is my query:-
INSERT INTO [BP].[users](id,username,email,contact,status) VALUES
('12','sujata','td@hh.com','8588841506','0'),
('13','sonali','th@wq.com','7894561231','0'),
('14','khushboo','tr@lp.com','7894561230','0')
It shows me this error message always:-
Msg 103010, Level 16, State 1, Line 20
Parse error at line: 2, column: 49: Incorrect syntax near ','.
This is my query from php file:-
$query = "INSERT INTO users(id,username,email,contact,status,num_update) VALUES $import_data ;
This is what import data returns
('12','sujata','td@hh.com','8588841506','0'),('13','sonali','th@wq.com','7894561231','0'),('14','khushboo','tr@lp.com','7894561230','0')
When I print the query it shows:-
INSERT INTO users(id,username,email,contact,status) VALUES ('12','sujata','td@hh.com','8588841506','0'),('13','sonali','th@wq.com','7894561231','0'),('14','khushboo','tr@lp.com','7894561230','0')
When I print Sql Error,it shows:-
SQLSTATE: 42000
code: 103010
message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Parse error at line: 1, column: 104: Incorrect syntax near ','.
SQLSTATE: 42000 code: 103010 message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Parse error at line: 1, column: 104: Incorrect syntax near ','.
Try this
INSERT INTO [BP].[users](id,username,email,contact,status)
select '12','sujata','td@hh.com','8588841506','0'
union
select '13','sonali','th@wq.com','7894561231','0'
union
select '14','khushboo','tr@lp.com','7894561230','0'
Actually my php skill not wery good. But I suggest an approach for solve a dynamic one. First you can parse your string with regex or if value is an array you can loop at other ways
('12','sujata','td@hh.com','8588841506','0'),
('13','sonali','th@wq.com','7894561231','0'),
('14','khushboo','tr@lp.com','7894561230','0')
Then you can insert per row
if you have csv
file then you need to do run following code to insert data in table
$query = <<<eof
LOAD DATA INFILE 'your csv file name'
INTO TABLE BP_users
FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '
'
(id,username,email,contact,status)
eof;
$db->query($query);