Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alok Mohanty  >  multipleInsert  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Demo file
Class: multipleInsert
Mutiple record Insertion in to a single table
Author: By
Last change:
Date: 2004-02-09 20:41
Size: 1,784 bytes
 

Contents

Class file image Download
<?php
/*
#####################################################################
# File Name : example.php
# Author : Alok Mohanty
# Last Modify : May 28,2003
# License : GPL
# Contact Info
# E-Mail : alok_r_mohanty@yahoo.com
######################################################################
*/

include('multipleInsert.inc');

/* ############ Configuration Block : Start ########### */

$dbname 'mydb';             // MYSQL DataBase Name
$dbhost 'localhost';        // MYSQL Host Name
$dbuser 'root';             // User Name
$dbpwd '' ;                 // Password


$table_src 'student';                   // Source Table
$field_arr_src = Array(std_name,std_age); // Field Names of Source Table


$table_desn 'student_dummy';     // Destination Table
$field_arr_desn = Array(name,age); // Field Names of Destination Table


/* ########### End Configuration ###################### */


$link mysql_connect($dbhost$dbuser$dbpwd) or die ("unable to connect");
mysql_select_db($dbname,$link)or die("could not select database") ;


$select_query "SELECT ".implode (","$field_arr_src)." FROM ".$table_src;
$select_result mysql_query($select_query);
$select_count mysql_num_rows($select_result);


if(
$select_count>0)
{
$counter 0;

  while(
$sel_row mysql_fetch_array($select_result))
  {
      for(
$i=0;$i<count($field_arr_src);$i++)
      {
      
$data_arr[$counter][] = addslashes($sel_row[$field_arr_src[$i]]);
      }

  
$counter++;
  }
}


/* ######### Applying Multi-Insert Class ############ */

$MI = new multiInsert($table_desn,$field_arr_desn,$data_arr);
$requiredQuery $MI->generateQuery();

mysql_query($requiredQuery) or die(mysql_error());

echo(
'Data Inserted');

?>