Re: Simple question on arrays and sql



Captain Paralytic wrote:
On 31 Mar, 16:22, sheldonlg <sheldonlg> wrote:
Given that I have a 2D array in php, is there a sql syntax to insert the
entire array at once?

For example if I retrieve a set of data from one table in the database
with keys A, B and C, and suppose there are 100 records, and I build an
array $arr consisting of

$arr[$i]['A'], $arr[$i]['B'], and $arr[$i]['C']

where $i goes from 0 to 99,

is there a syntax to insert the entire $arr array at one time into
fields A, B, and C of a new table?

I really would like to avoid having 100 sql insert calls.
BTW, this is for an Oracle DB.

In the past I have only had to insert a few records at a time, so i
simply did multiple inserts. Of course for Oracle I could do the same
and only do a commit after all are done.

Why not use an INSERT ... SELECT syntax and do it all in SQL?

Sometimes the most obvious solution is the last one you see. This will do it:

INSERT INTO AA (A, B, C) SELECT A, B, C FROM BB WHERE blahblahblah

Thank you
.



Relevant Pages

  • Handling case of field names in multiple dbs
    ... I get the returned row fields in an associative array, ... element key is the field name and the element value is the field ... The problem is that MS SQL returns field names in mixed case ... define the field names in MS SQL in the first place), while Oracle ...
    (comp.lang.php)
  • Re: .join() !== + a + b; // for some a and b
    ... The one seemed obvious until your more detailed explanation below, ... that made it necessary to look deeper into the syntax. ... one an Array object reference and one ... seems wrong with the expression evaluation on the left side of the logical ...
    (comp.lang.javascript)
  • Re: How to do "Compile time" initialization of record array?
    ... It should be noted that there is proposed syntax for C# 3.0 which will ... public struct MyStruct ... What actually gets compiled is the same array initialization as there is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: It Hurts When I Do This
    ... We do have a syntax that means the entire array - the array name. ... I disagree that it helps to use a special notation to indicate that ... I think it a mistake to throw all this kind of thing in the language. ...
    (comp.lang.fortran)
  • Re: IVF is a wonderful compiler (was IVF continues to disappoint (relatively))
    ... In quite a few of these cases g95 is still unable to detect ... array syntax. ... Lots of competing compilers rewrite all array syntax into F77 ...
    (comp.lang.fortran)