PHP Classes

File: Sql_Compiler/Sql_CompilerInsert.class.php

Recommend this page to a friend!
  Classes of Tom Schaefer   SQL Parse and Compile   Sql_Compiler/Sql_CompilerInsert.class.php  
File: Sql_Compiler/Sql_CompilerInsert.class.php
Role: Class source
Content type: text/plain
Description: compile insert statement
Class: SQL Parse and Compile
Parse and compose SQL queries programatically
Author: By
Last change: Many thanks to vote for second place

sample bulk insert statement


# multiple insert data
$data = array(
array(
array('Value'=>'Davolio', 'Type'=>'text_val'),
array('Value'=>'Nancy', 'Type'=>'text_val'),
array('Value'=>'1992-05-01', 'Type'=>'text_val'),
array('Value'=>'Seattle', 'Type'=>'text_val'),
array('Value'=>'WA', 'Type'=>'text_val'),
array('Value'=>'98122', 'Type'=>'int_val'),
array('Value'=>'United States', 'Type'=>'text_val'),
array('Value'=>'(206) 555-9857', 'Type'=>'text_val'),
array('Value'=>'5467', 'Type'=>'int_val'),
array('Value'=>'', 'Type'=>'text_val')
),
array(
array('Value'=>'Smith', 'Type'=>'text_val'),
array('Value'=>'Tom', 'Type'=>'text_val'),
array('Value'=>'1991-02-01', 'Type'=>'text_val'),
array('Value'=>'New York', 'Type'=>'text_val'),
array('Value'=>'NY', 'Type'=>'text_val'),
array('Value'=>'12345', 'Type'=>'int_val'),
array('Value'=>'United States', 'Type'=>'text_val'),
array('Value'=>'(555) 555-9857', 'Type'=>'text_val'),
array('Value'=>'1234', 'Type'=>'int_val'),
array('Value'=>'some text here', 'Type'=>'text_val')
),
array(
array('Value'=>'Doe', 'Type'=>'text_val'),
array('Value'=>'John', 'Type'=>'text_val'),
array('Value'=>'1993-04-01', 'Type'=>'text_val'),
array('Value'=>'Los Angeles', 'Type'=>'text_val'),
array('Value'=>'CA', 'Type'=>'text_val'),
array('Value'=>'12345', 'Type'=>'int_val'),
array('Value'=>'United States', 'Type'=>'text_val'),
array('Value'=>'(555) 555-9857', 'Type'=>'text_val'),
array('Value'=>'4321', 'Type'=>'int_val'),
array('Value'=>'Some text here', 'Type'=>'text_val')
),
);

$sqlObject = new Sql();
$sqlObject ->setCommand("insert")
->addTableNames("northwind.employees")
->setColumnNames(
array(
"LastName",
"FirstName",
"BirthDate",
"HireDate",
"Address",
"City",
"Region",
"PostalCode",
"Country",
"HomePhone"
)
);
$sqlObject->setValues($data);

pdbg($sqlObject, "orange", __LINE__,__FILE__);
pdbg($sqlObject->compile(), "orange", __LINE__,__FILE__);

Date: 15 years ago
Size: 3,140 bytes

You need to be a registered user and login to get this file.

1,615,217 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on: