php - what are all the possible ways to insert a array in mysql database -
I have a JSON array that contains a date, a value, and a quantity in events, therefore:
< ["May 09 2014", 1.01171], ["11 May 2014", 1.56,87]]- php loop (but in each list) can be up to <200%
- Parsing an XML string inside the stored procedure
- The stored procedure Make some crazy arguments to parse a string inside
Is there any other way?
First of all, create a PHP array from JSON:
$ jsonString = '[["May 09 2014", 1.17, 63], ["May 10 2014", 1.01,171], ["May 11 2014", 1.56,87]];'; $ Array = json_decode ($ jsonString); Now in that array, generate inserts and write everything in one go. 200 entries are not too much for the loop. "INSERT"; $ insert = []; $ Params = []; Forex currency (
$ query = "table name (` data`, `value`,` quantity`) $ Index = & gt; $ array as $ array] {$ insert [] = "(: data {$ index}, value: {$ index}, quantity {$ index})"; $ params [] = [": Data {$ index}" = & gt; $ line [0], ": value {$ index}" = & gt; $ line [1], ": quantity {$ index}" = & gt; Line [2],];} $ Sql = $ db- & gt; create ($ query.implode (',', $ insertion)); $ Sql-> execution ($ param Peter);
Comments
Post a Comment