Skip to content
Advertisement

Can I call a stored procedure on each iteration of an array? PHP

I want to loop through an associative array that represents a table’s columns and values, and call a stored procedure on each iteration that will insert each value into its respective column. The assoc. array and loop looks like this:

JavaScript

The stored procedure looks like this:

JavaScript

Is this possible to do? Or is there a better alternative? Many thanks

Advertisement

Answer

do you know what the prepared statement would look like in this instance?

JavaScript

Alternatively you may concat ALL parameters values into the query text:

JavaScript

Caution.

The columnName parameter value is inserted into SQL query text as-is – so injection is possible. You must add the code which controls this parameter value. For example you may check that the column with provided name exists in table structure.

Another 2 parameters cannot be a source of injection due to their numeric datatype.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement