php – Insert data into MSSQL-ThrowExceptions

Exception or error:

I’m trying to insert data from php into MSSQL DB.
I’m able to do this:

sqlsrv_query($conn,"insert into <DB_Name> (First_Name,Last_Name) VALUES ('Dani','Yorgen')");

The thing is that i have an array which i want to use it instead of using static values.
i found this command:

$columns = implode(", ", array_values($headers));

this works perfeclty for me!

however when itry to do the same for the data it doesnt come as i want.
the result comes like this:
First_Name,Last_Name
when i need it to look like this:
‘First_Name’,’Last_Name’

any ideas?

thanks in advance.

How to solve:

I managed to find the solution after bashing my head a little bit longer 🙂
it should go like this:

$columns = "'" . implode(",", array_values($headers)) . "'";

hope it will help those who needs.

Leave a Reply

Your email address will not be published. Required fields are marked *